Java output type question

Q.  Give the Output for the following program?

class Char {
public static void main(String args[]) {
char ch1, ch2;
ch1 = 88; // code for X
ch2 = 'Y';
System.out.print("ch1 and ch2: ");
System.out.println(ch1 + " " + ch2);
}
}

- Published on 21 Jul 15

a. ch1 and ch2: X Y
b. ch1 and ch2: x y
c. ch1 and ch2: 1 3
d. None of the above

ANSWER: ch1 and ch2: X Y
 

    Discussion

  • Jamaysha   -Posted on 09 Jun 19
    System.out.print("ch1 and ch2: ");

    Statement 1 : "ch1 and ch2" - value within double quotation is the string not variable . So the output of the statement 1 is ch1 and ch2

    System.out.println(ch1 + " " + ch2); the value without double quotation which means ch1 and ch2 are variables. ch1 value is X and ch2 value is Y . So the output of the statement is X Y
  • Jamaysha   -Posted on 09 Jun 19
    System.out.print("ch1 and ch2: ");

    Statement 1 : "ch1 and ch2" - value within double quotation is the string not variable . So the output of the statement 1 is ch1 and ch2

    System.out.println(ch1 + " " + ch2); the value without double quotation which means ch1 and ch2 are variables. ch1 value is X and ch2 value is Y . So the output of the statement is X Y

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)