1.
What all gets printed when the following gets compiled and run?
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
here
A. 
B. 
C. 
D. 
2.
What will be the output of the program when to try to execute
public class Arizona {
int id;
String name;
public Arizona() {
this(”aryabhatta”);
System.out.print(”first “);
}
public Arizona(String name) {
this(420, “aryabhatta”);
System.out.print(”second “);
}
public Arizona(int id, String name) {
this.id = id;
this.name = name;
System.out.print(”third “);
}
public static void main(String[] args) {
Arizona b = new Arizona();
System.out.print(b.name +“ “ + b.id);
}
}
A. 
First second third aryabhatta 420
B. 
Third second first aryabhatta 0
C. 
Third second first aryabhatta 420
D. 
3.
Consider the following code that contains the class definitions for class ABC, XYZ, and Alphabet. What will be the output of this code?
class ABC extends XYZ
{
ABC () {
super ();
System.out.print (" ABC ");
}
public static void main (String args[])
{
XYZ x1 = new ABC ();
}
}
class XYZ extends Alphabet
{
XYZ ()
{
System.out.print (" XYZ ");
}
}
class Alphabet
{
void Alphabet ()
{
System.out.print (" Alphabet ");
}
}
A. 
B. 
C. 
D. 
4.
What will be the result of compiling and running the following code ?
public class LoopCheck {
public static void main(String args[]) {
int i = 0;
int x = 10;
while ( x > 6 ) {
System.out.print(++i + " ");
x--;
}
}
}
Select the correct answer :
A. 
B. 
C. 
D. 
5.
What all gets printed when the following program is compiled and run. Select the two correct answers.
public class test {
public static void main(String args[]) {
int i, j=1;
i = (j>1)?2:1;
switch(i) {
case 0: System.out.println(0); break;
case 1: System.out.println(1);
case 2: System.out.println(2); break;
case 3: System.out.println(3); break;
}
}
}
A. 
B. 
C. 
D. 
6.
________________________ makes Java platform-independent.
A. 
B. 
C. 
D. 
7.
Byte b = 50 ;
b = b * 2 ;
System.out.println( " b = " + b ) ;
The above fraction of code prints b = 100.
8.
Final methods cannot be overridden but overloaded ?
9.
Class Weather
{
static boolean isRaining;
public static void main(String args[])
{
System.out.print(isRaining);
}
}
A. 
B. 
C. 
Does not compile as boolean is not initialized
D. 
10.
What is the name of the method used to start a thread execution?
A. 
B. 
C. 
D. 
11.
What is the output of following block of program ?
boolean var = false;
if(var = true) {
System.out.println(“TRUE”);
} else {
System.out.println(“FALSE”);
}
12.
Which interface provides the capability to store objects using a key-value pair?
A. 
B. 
C. 
D. 
13.
What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}
1. A
2. B
3. C
4. D
A. 
B. 
C. 
D. 
14.
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error();
}
}
A. 
BC is printed before exiting with an error message.
B. 
C. 
D. 
C is printed before exiting with an error message.
15.
Can there be an abstract class with no abstract methods in it?
16.
What will be the output of the program?
public class WithoutBook
{
static int x;
boolean catch1()
{
x++;
return true;
}
public static void main(String[] args)
{
if ((catch1() | catch1()) || catch1())
x++;
System.out.println(x);
}
}
A. 
B. 
C. 
D. 
17.
What will be the output of the program?
String s = "ABC";
s.toLowerCase();
s += "def";
System.out.println(s);
A. 
B. 
C. 
D. 
18.
What will be the output of the program?
try
{
Float f1 = new Float("3.0");
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e)
{
System.out.println("bad number");
}
A. 
Compilation fails on line 3.
B. 
Compilation fails on line 5.
C. 
D. 
19.
What will be the output of the program?
String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
A. 
B. 
C. 
D. 
20.
What should be at line number 3 to get the total sum of array "sum" ?
public int totalSum( int[] sum ){
int a, b= 0 ;
//which 'for' loop should be here(line :3)
{
b += sum[ a++ ] ;
}
return b ;
}
A. 
B. 
For( a= 0 ; a< sum.length ; )
C. 
For( a = 0 ; a< sum.length() ; a++ )
D. 
For( a = 0 ; a< sum.length ; a++ )
21.
Public class Child extends Parent {
public static void main(String[] args) {
Parent p = new Child();
p.method();
}
void method(){
System.out.println("Child method");
}
}
class Parent {
void method(){
System.out.println("Parent method");
}
}
What is the output?
A. 
B. 
C. 
D. 
22.
What will be the output of the program?
public class WBFoo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
A. 
B. 
C. 
An exception is thrown at runtime
D. 
The code runs with no output
23.
Which of the following are true about interfaces. Select the correct answer.
A. 
Methods declared in interfaces are implicitly private.
B. 
Variables declared in interfaces are implicitly public, static, and final.
C. 
The keyword implements indicate that an interface inherits from another.
D. 
An interface can not extend any number of interfaces.
24.
Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
A. 
B. 
C. 
D. 
25.
Public class CoreJavaOnlineTest1 {
public static void main(String[] args) {
String s1 = "withoutbook";
String s2 = s1;
s1 = null;
System.out.println("s1:"+s1+" s2:"+s2);
}
}
A. 
B. 
C. 
D.