JavaQuizzes

Multiple Choice Question

Consider the following class...

class Test{

public static void main(String[ ] args){

int[] a = { 1, 2, 3, 4 };

int[] b = { 2, 3, 1, 0 };

System.out.println( a [ (a = b)[3] ] );

}

}

What will it print when compiled and run ?

Select 1 option

A. It will not compile.

B. It will throw ArrayIndexOutOfBoundsException when run.

C. It will print 1.

D. It will print 3.

E. It will print 4

F. It will print 2

Multiple Choice Question

What will be the result of trying to compile and execute of the following program?

public class TestClass{

public static void main(String args[] ){

int i = 0 ;

int[] iA = {10, 20} ;

iA[i] = i = 40 ;

System.out.println(""+ iA[ 0 ] + " " + iA[ 1 ] + " "+i) ;

}

}

Select 1 option

A. It will throw ArrayIndexOutofBoundsException at Runtime.

B. Compile time Error.

C. It will prints 10 20 40

D. It will prints 40 20 40

E. It will prints 0 20 40

Multiple Choice Question

Is it possible to create arrays of length zero?

 

Select 1 option

A. Yes, you can create arrays of any type with length zero.

B. Yes, but only for primitive datatypes.

C. Yes, but only for arrays of object references.

D. Yes, and it is same as a null Array.

E. No, arrays of length zero do not exist in Java.

True or False

class Test{

public static int[ ] getArray() { return null; }

public static void main(String[] args){

int index = 1;

try{

getArray()[index=2]++;

}

catch (Exception e){ } //empty catch

System.out.println("index = " + index);

}

}

 

Select 1 option

A. True

B. False

Multiple Choice Question

import java.util.* ;

public class ListTest{

public static void main(String args[]){

List s1 = new ArrayList( );

s1.add("a");

s1.add("b");

s1.add(1, "c");

List s2 = new ArrayList( s1.subList(1, 1) );

s1.addAll(s2);

System.out.println(s1);

}  }

What sequence of digits will the following program print?

 

Select 1 option

A. The sequence a, b, c is printed.

B. The sequence a, b, c, b is printed.

C. The sequence a, c, b, c is printed.

D. The sequence a, c, b is printed.

E. None of the above.

Multiple Choice Question

What will the program print?

class Parent{
	
	public void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Multiple Choice Question

What will the program print?

class Parent{
	
	public static void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public static void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Multiple Choice Question

What will the program print?

class Parent{
	
	public static void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Multiple Choice Question

What will the program print?

class Parent{
	
	public void myMethod()
	{
		System.out.println("Parent myMethod");
	}
}

class Child extends Parent{
	
	public static void myMethod()
	{
		System.out.println("Child myMethod");
	}
}

class OverridingCheck {

	public static void main(String args[])
	{
		Parent p = new Child();
		p.myMethod();
	}

}

 

Select 1 option

A. Prints "Parent myMethod"

B. Prints "Child myMethod"

C. Compilation Fails

D. Exception at Runtime

Multiple Choice Question

Given:

public class ExceptionCheck {
	
	static int i = 10;
	
	public static void main (String[] argds)
	{
		System.out.println(myMethod());
		System.out.println(i);
	}
	
	public static int myMethod()
	{
		try{
			throw new Exception();
		}
		catch(Exception e)
		{
			return i;
		}
		finally{
			i = 12;
		}
	}
}

 

Select 1 option

A. Compilation Fail

B. Print 10 and 12.

C. Print 10 and 10.

D. Print 12 and 12.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!