Which of the following statements are acceptable?
Select 4 options
A. Object o = new java.io.File ("a.txt"); (Assume that java.io.File is a valid class.) B. Boolean bool = false; /*w w w. j a va 2 s . co m*/ C. char ch = 10; D. Thread t = new Runnable (); (Assume that Runnable is a valid interface.) E. Runnable r = new Thread (); (Assume that Thread is a class that implements Runnable interface)
Correct Options are : A B C E
A. is correct. This is valid because every object in Java is an Object.
B. is correct.
bool is a variable of type Boolean and not of a primitive type boolean.
However this is still valid because Java performs auto-boxing (and unboxing) for primitives and their wrapper types which allows false to be automatically be boxed into a Boolean false object.
C. is correct. Because 10 can fit into a char.
D. is wrong.
Since Runnable is an interface, it cannot be instantiated like this.
But you can do:
Runnable r = new Runnable (){ public void run (){ } };
E. is correct. Since Thread implements Runnable, this is a valid assignment.