JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
517

Given:

public class TestClass{
public static void main(String[] args){
int i = Integer.parseInt(args[1]);
System.out.println(args[i]);
}
}

What will happen when you compile and run the above program using the following command line: java TestClass 1 2

Select 1 option

A. It will print 1
B. It will print 2
C. It will print some junk value.
D. It will throw ArrayIndexOutOfBoundsException.
E. It will throw NumberFormatException

Multiple Choice Question

QID: 
518

Assume that a method named 'method1' contains code which may raise a non-runtime (checked) Exception. What is the correct way to declare that method so that it indicates that it expects the caller to handle that exception?

Select 2 options

A. public void method1() throws Throwable
B. public void method1() throw Exception
C. public void method1() throw new Exception
D. public void method1() throws Exception
E. public void method1()

Multiple Choice Question

QID: 
519

What is wrong with the following code written in a single file named TestClass.java?

class SomeThrowable extends Throwable { }
class MyThrowable extends SomeThrowable { }
public class TestClass{
public static void main(String args[]) throws SomeThrowable{
try{
m1();
}catch(SomeThrowable e){
throw e;
}finally{
System.out.println("Done");
}
}
 public static void m1() throws MyThrowable{
throw new MyThrowable();
}  
 }

Select 2 options

A. The main declares that it throws SomeThrowable but throws MyThrowable.
B. You cannot have more than 2 classes in one file.
C. The catch block in the main method must declare that it catches MyThrowable rather than SomeThrowable.
D. There is nothing wrong with the code.
E. Done will be printed.

Multiple Choice Question

QID: 
520

What will be the output of the following program:

public class TestClass{
public static void main(String args[]){
try{
m1();
}catch(IndexOutOfBoundsException e){
System.out.println("1");
throw new NullPointerException();
}catch(NullPointerException e){
System.out.println("2");
return;
}catch (Exception e) {
System.out.println("3");
}finally{
System.out.println("4");
}
System.out.println("END");
}     // IndexOutOfBoundsException is a subclass of RuntimeException.
static void m1(){
System.out.println("m1 Starts");
throw new IndexOutOfBoundsException( "Big Bang " );
}
}

Select 3 options

A. The program will print m1 Starts.
B. The program will print m1 Starts, 1 and 4, in that order.
C. The program will print m1 Starts, 1 and 2, in that order.
D. The program will print m1 Starts, 1, 2 and 4 in that order.
E. END will not be printed.

Multiple Choice Question

QID: 
521

Considering the following program, which of the options are true?

public class FinallyTest{
public static void main(String args[]){
try{
if (args.length == 0) return;
else throw new Exception("Some Exception");
}
catch(Exception e){
System.out.println("Exception in Main");
}  finally{
System.out.println("The end");
}
} }

Select 2 options

A. If run with no arguments, the program will only print 'The end'.
B. If run with one argument, the program will only print 'The end'.
C. If run with one argument, the program will print 'Exception in Main' and 'The end'.
D. If run with one argument, the program will only print 'Exception in Main'.
E. Only one of the above is correct.

Pages

Search the Web

Custom Search

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