Which of the following are valid statements?
1) System.out.println(1+1);
2) int i=2+'2';
3) c
4) byte b=255;
Answer:
1) System.out.println(1+1);
2) int i=2+'2';
Option 3 is not valid because single quotes are used to indicate a character constant and not a string. Several people have emailed me to say that option 3 will compile. When they eventually compiled the exact code they have agreed, it will not compile. Let me re-state that
String s="on"+'one'; Will NOT compile.
Option 4 will not compile because 255 is out of the range of a byte
No comments:
Post a Comment