Set 32

Multiple Choice Question

QID: 
251

What letters, and in what order, will be printed when the following program is compiled and run?

public class FinallyTest{
public static void main(String args[]) throws Exception{
try{
m1();
System.out.println("A");
}
finally{
System.out.println("B");
}
System.out.println("C");
}
public static void m1() throws Exception { throw new Exception(); }
}

Select 1 option

A. It will print C and B, in that order.
B. It will print A and B, in that order.
C. It will print B and throw Exception.
D. It will print A, B and C in that order.
E. Compile time error.

Multiple Choice Question

QID: 
250

What is the result of compiling and running this code?

class MyException extends Throwable{}
class MyException1 extends MyException{}
class MyException2 extends MyException{}
class MyException3 extends MyException2{}
public class ExceptionTest{
void myMethod() throws MyException{
throw new MyException3();
}public static void main(String[] args){
ExceptionTest et = new ExceptionTest();
try{
et.myMethod();
}catch(MyException me){
System.out.println("MyException thrown");
}catch(MyException3 me3){
System.out.println("MyException3 thrown");
}finally{
System.out.println(" Done");
}  }  }

Select 1 option

A. MyException thrown
B. MyException3 thrown
C. MyException thrown Done
D. MyException3 thrown Done
E. It fails to compile

Multiple Choice Question

QID: 
249

A Java programmer is developing a desktop application. Which of the following exceptions would be appropriate for him to throw explicitly from his code?

Select 1 option

A. NullPointerException
B. ClassCastException
C. ArrayIndexOutofBoundsException
D. Exception
E. NoClassDefFoundError

Multiple Choice Question

QID: 
248

Which statements regarding the following code are correct?

class Base{
void method1() throws java.io.IOException, NullPointerException{
someMethod("arguments");
// some I/O operations
}
int someMethod(String str){
if(str == null) throw new NullPointerException();
else return str.length();
}
}public class NewBase extends Base{
void method1(){
someMethod("args");
}
}

Select 2 options

A. method1 in class NewBase does not need to specify any exceptions.
B. The code will not compile because RuntimeExceptions cannot be given in throws clause.
C. method1 in class NewBase must at least give IOException in its throws clause.
D. method1 in class NewBase must at least give NullpointerException in its throws clause.
E. There is no problem with the code.

Multiple Choice Question

QID: 
247

What will be the output when the following program is run?

package exceptions;
public class TestClass {
public static void main(String[] args) {
try{
doTest();
}catch(MyException me){
System.out.println(me);
}   }static void doTest() throws MyException{
int[] array = new int[10];
array[10] = 1000;
doAnotherTest();
}static void doAnotherTest() throws MyException{
throw new MyException("Exception from doAnotherTest");
}   }class MyException extends Exception {
public MyException(String msg){
super(msg); }  }

Select 1 option

A. Exception in thread "main"
         java.lang.ArrayIndexOutOfBoundsException: 10
        at exceptions.TestClass.doTest(TestClass.java:24)
        at exceptions.TestClass.main(TestClass.java:14)
B. Error in thread "main" java.lang.ArrayIndexOutOfBoundsException
C. exceptions.MyException: Exception from doAnotherTest
D. exceptions.MyException: Exception from doAnotherTest
       at exceptions.TestClass.doAnotherTest(TestClass.java:29)
       at exceptions.TestClass.doTest(TestClass.java:25)
       at exceptions.TestClass.main(TestClass.java:14)

Pages

Search the Web

Custom Search

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

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)