Java Interview Questions On Variables |
27. What is the result when you compile and run the following code?
public class TestLocal {
public static void main(String args[]) {
String s[] = new String[6];
System.out.print(s[6]);
}
}
[a] A null is printed
[b] Compile time error
[c] Exception is thrown
[d] null followed by 0 is printed on the screen
Answer
[c] Exception is thrown
|
28. Which of the declaration following compile correctly?
[a] double d = 10.2f;
[b] float f = 10L;
[c] byte b = 10.0d;
[d] byte b1 = 155;
Answer
[a] double d = 10.2f;
[b] float f = 10L; |
29. Which of the declaration following compile correctly?
[a] String s = "Test";
[b] float f = 10L;
[c] byte b = true;
[d] boolean b1 = false;
Answer
[a] String s = "Test";
[b] float f = 10L;
[d] boolean b1 = false; |
30. Which of the declaration following compile correctly?
[a] double d = (byte)15.0d;
[b] long k = 'A';
[c] byte b = 10.0d;
[d] byte b1 = 155;
Answer
[a] double d = (byte)15.0d;
[b] long k = 'A'; |