Question 1
Question
What will be the output of the program?<br>
Answer
-
Pine
-
Oak
-
Tree
-
Forest
-
Oops
Question 2
Question
Select how you would run your program to cause it to print: Arg is 2 <br>
Answer
-
java Myfile 2 2 2
-
java Myfile 1 2 2 3 4
-
java Myfile 1 3 2 2
-
java Myfile 1 2 2 2
-
java Myfile 0 1 2 3
Question 3
Question
What is the prototype of the default constructor?<br>
Answer
-
Test()
-
Test
-
public Test()
-
public Test(void)
-
Test(void)
Question 4
Question
What is the widest valid returnType for methodA in line 3?<br>
Answer
-
int
-
long
-
byte
-
double
-
void
Question 5
Question
Which is valid in a class that extends class A?<br>
Answer
-
public int method1(int a, int b) {return 0; }
-
private int method1(int a, int b) {return 0; }
-
protected static int method1(int a, int b) {return 0; }
-
public long method1(int a, int b) {return 0; }
-
public static int method1(int a, int b) {return 0; }
Question 6
Question
What will be the output of the program?<br>
Answer
-
one two three four
-
one two three four one
-
four three two one
-
four one three two
Question 7
Question
What will be the output of the program?<br>
Question 8
Question
What will be the output of the program after the running program in such way :/> java Test red green blue?<br>
Answer
-
baz =
-
baz = blue
-
baz = null
-
Runtime Exception
-
Compilation Error
Question 9
Question
What will be the output of the program? <br>
Answer
-
It will print the numbers from 0 to 19 sequentially
-
It will print the numbers from 1 to 20 sequentially
-
It will print the numbers from 0 to 19 but the order is not determined
-
It will print the numbers from 1 to 20 but the order is not determined
-
It will print the numbers from 0 to 9 two times, but the order is not determined
Question 10
Question
The following block of code creates a Thread using a Runnable target: <br>
Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
Answer
-
public class MyRunnable extends Runnable{public void run(){}}
-
public class MyRunnable extends Object{public void run(){}}
-
public class MyRunnable implements Runnable{public void run(){}}
-
public class MyRunnable implements Runnable{void run(){}}
-
public class MyRunnable implements Thread{void run(){}}
Question 11
Question
What will be the output of the program?<br>
Question 12
Question
Which of these will create and start this thread? <br>
Answer
-
new Runnable(MyRunnable).start();
-
new Thread(MyRunnable).run();
-
new Thread(new MyRunnable()).start();
-
new MyRunnable().start();
-
new Runnable(MyRunnable).run();
Question 13
Question
What will be an output? <br>
Answer
-
true true
-
true false
-
false true
-
false false
-
Runtime error will occur
Question 14
Question
What will be an output? <br>
Answer
-
24
-
30
-
120
-
720
-
Compilation Error
Question 15
Question
What will be an output? <br>
Answer
-
1
-
0
-
5
-
15
-
Compilation Error
-
Runtime Error
Question 16
Question
What will be an output? <br>
Answer
-
1
-
0
-
12
-
78
-
Compilation error
-
Runtime error
Question 17
Question
What will be the output of the program? <br>
Answer
-
Got the exception 10
-
Got the exception e
-
Compilation error
-
Runtime error
Question 18
Question
What will be the output of the program? <br>
Question 19
Question
What will be the output of the program? <br>
Question 20
Question
What will be the output of the program? <br>
Answer
-
Caught base class exception
-
Caught derived class exception
-
Caught base class exception <br> Caught derived class exception
-
Compilation error because derived is not throwable
-
Compilation error because base class exception is caught before derived class
Question 21
Question
What will be the output of the program? <br>
Question 22
Question
What will be the output of the program?<br>
Question 23
Question
What will be the output of the program? <br>
Answer
-
Derived::show() called
-
Base::show() called
-
Compilation error
-
Runtime error
Question 24
Question
What will be the output of the program? <br>
Answer
-
Derived::show() called
-
Base::show() called
-
Compilation error
-
Runtime error
Question 25
Question
What will be the output of the program? <br>
Answer
-
Base
-
Derived
-
Compilation error
-
Runtime error
Question 26
Question
What will be the output of the program? <br>
Answer
-
Compilation error in super.super.Print()
-
Grandparent’s print <br> Child’s Print()
-
Grandparent’s print <br> Parent’s Print <br> Child’s Print()
-
Runtime error
Question 27
Question
What will be the output of the program? <br>
Question 28
Question
What will be the output of the program? <br>
Answer
-
20
-
0
-
Compilation error
-
Runtime error
Question 29
Question
What will be the output of the program? <br>
Answer
-
s1 == s2 is: true
-
s1 == s2 is: false
-
true
-
false
-
compilation error
-
runtime exception
Question 30
Question
What will be the output of the following program? <br>
Answer
-
BD
-
ABDE
-
BCDE
-
BCD
-
BDE
-
ABCE
-
ABCD
-
ABD
Question 31
Question
What will be the output of the following code? <br>
Question 32
Question
What will be the output of the program? <br>
Question 33
Question
What will be the output of the program? <br>
Answer
-
ABCD
-
ACD
-
ABD
-
BCD
-
BC
-
BD
-
CD
Question 34
Question
What will be the output of the program? <br>
Answer
-
Hello world
-
Hello world Finally executing
-
Finally executing
-
Nothing. The program will not compile because no exceptions are specified
-
Nothing. The program will not compile because no catch clauses are specified
Question 35
Question
What will be the output of the program? <br>
Answer
-
Ex0 caught
-
Exception caught
-
Compilation fails on line 2
-
Compilation fails on line 9
-
Compilation fails on line 11
Question 36
Question
What line of code should replace the missing statement to make this program compile? <br>
Question 37
Question
What will be the output of the program?<br>
Question 38
Question
Given <br> <b> Note: The keyword "instanceof" is use to check whether an object is of a particular type</b><br>What is the result?
Answer
-
Will produce output as false
-
Compilation fails due to error at line 3
-
Compilation fails due to error at line 4
-
Length of this array is 3
-
Will produce output a true
Question 39
Question
What will be the output? <br>
Question 40
Question
What will be the output? <br>
Answer
-
Caught base class exception
-
Caught derived class exception
-
Compiler error because derived is not throwable
-
Compiler error because base class exception is caught before derived class
Question 41
Question
What is the output of the following code segment? <br>
Question 42
Question
What are the values of I and product after this code is executed? <br>
Answer
-
9 and 366
-
9 and 336
-
8 and 42
-
8 and 336
Question 43
Question
What is the output of the following code fragment? <br>