Open In App
Related Articles

Output of Java Programs | Set 30

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
QUE.1 What is the output of this program ?
public class Prg {
    public static void main(String args[])
    {
        System.out.print('A' + 'B');
    }
}

                    
OPTION a) AB b) 195 c) 131 d) Error
Answer: c
Explanation: Here, ‘A’ and ‘B’ are not strings they are characters. ‘A’ and ‘B’ will not concatenate. The ASCII of the ‘A’ and ‘B’ will be added. The value of ‘A’ is 65 and ‘B’ is 66. Hence Output will be 131. QUE.2 What is the output of this program?
public class Prg {
    public static void main(String args[])
    {
        System.out.print("A" + "B" + 'A' + 10);
    }
}

                    
OPTION a) ABA10 b) AB65 c) Error d) AB
Answer :  a
Explanation: If you try to concatenate any different types of data like integer, character, float with string value, the result will be a string. So ‘A’ will be concatenated with “AB” and answer will be “ABA”. QUE. 3 What is the output of this program ?
public
class Prg {
    public static void main(String args[])
    {
        System.out.print(20 + 1.34f + "A" + "B");
    }
}

                    
OPTION a) 201.34AB b) 201.34fAB c) 21.34AB 4) Error
Answer : c
Explanation : Similar data types are added and then converted to string. 20 and 1.34f will be added and then 21.34 will be concatenated with “A” and “B”, hence output will be 21.34AB. QUE.4 What is the output?
public class Prg {
    public static void main(String[] args)
    {
        char[] str = { 'i', 'n', 'c', 'l', 'u'
                'd', 'e', 'h', 'e', 'l', 'p' };
        System.out.println(str.toString());
    }
}

                    
OPTION a) includehelp b) Error c) [C@19e0bfd (Memory Address) d) NULL
Answer: c
Explanation : [C@19e0bfd (Memory Address) : str is a character array, if you try to print str.toString() it will not converted to string because str is an object of character array that will print an address in string format. QUE.5 what is output of this program?
public class prg {
    public static void main(String[] args)
    {
        System.out.print("Hello");
        System.out.println("Guys!");
    }
}

                    
OPTION a) HelloGuys! b) Hello Guys! c) Hello Guys! d) Compile with a Warning
Answer :  a
Explanation : System.out.print() does not print new line after printing string, while System.out.println(); prints new line after printing string. Hence output will be HelloGuys! and then new line.

Last Updated : 18 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads