What is the output of the following code when compiled and run? Select two correct answers. public class Question01 { public static void main(String[] args){ int y=0; //line 1 int x=z=1; //line 2 System.out.println(y+","+x+","+z); //line 3 } }
Prints 0,1,1
Error during compilation at line 1
E. Error during compilation at line 2
Error during compilation at line 3
What is the output of the following code when compiled and run? Select one correct answer. public class Question02 { public static void main(String[] args){ int j = 017; int i = (byte)j >> 2; //line 1 System.out.println(Integer.toBinaryString(i)); //line 2 } }
Prints 3
Prints 11
Prints 0
What is the output of the following code when compiled and run? Select one correct answer. import java.io.*; public class Question05 { public static void main(String[] args) { Question05Sub myref = new Question05Sub(); try{ myref.test(); }catch(IOException ioe){} } void test() throws IOException{ System.out.println("In Question05"); throw new IOException(); } } class Question05Sub extends Question05 { void test() { System.out.println("In Question05Sub"); } }
Prints: In Question05Sub
Prints: In Question05
Prints:In Question05In Question05Sub
The code does not compile.
Select three correct statements about the following code. public class Question20 { public static void main(String[] args) { Question20 myref = new Question20Sub(); try{ myref.test(); }catch(Exception e){} } void test() throws Exception{ System.out.println("In Question20"); throw new Exception(); } } class Question20Sub extends Question20 { void test() { System.out.println("In Question20Sub"); } }
The try-catch block that encloses myref.test(); is mandatory for the code to compile.
Prints: In Question20
Prints: In Question20Sub
Method test() in class Question20Sub has no obligation to declare a throws clause.
An exception is thrown at runtime.
What is the output of the following code when compiled and run? Select one correct answer. public class Question41{ public static void main(String[] args){ Object[] obj = new Object[3]; for(int i=0;i
Compilation error.
Prints: 1 3 4 true false true
Prints: 1 2 4 false false true
Prints: 3 4 true true true
None of the above.
When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.
True
False
All interface methods must be declared as public when implemented in a class.
A method in a class declared as static may be invoked simply by using the name of the method alone.
A static method can refer to any instance variable of the class.
Each method in a class must have a unique name.