Set 34

Multiple Choice Question

QID: 
527

A try statement must always have a ............. associated with it.

Select 1 option

A. catch 
B. throws 
C. finally 
D. catch, finally or both 
E. throw 

Multiple Choice Question

QID: 
526

What will be the output of the following program?

class TestClass{
public static void main(String[] args) throws Exception{
try{
amethod();
System.out.println("try");
}
catch(Exception e){
System.out.println("catch");
}
finally {
System.out.println("finally");
}
System.out.println("out");
}
public static void amethod(){ }
}

Select 1 option

A. try finally
B. try finally out
C. try out
D. catch finally out
E. It will not compile because amethod() does not throw any exception.

Multiple Choice Question

QID: 
525

What will be the output of the following class...

class Test{
public static void main(String[] args){
int j = 1;
try{
int i = doIt() / (j = 2);
} catch (Exception e){
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception { throw new Exception("FORGET }

Select 1 option

A. It will print j = 1;
B. It will print j = 2;
C. The value of j cannot be determined.
D. It will not compile.
E. None of the above.

Multiple Choice Question

QID: 
524

What will be the result of attempting to compile and run the following program?

public class TestClass{
public static void main(String args[]){
Exception e = null;
throw e;
}
}

Select 1 option

A. The code will fail to compile.
B. The program will fail to compile, since it cannot throw a null.
C. The program will compile without error and will throw an Exception when run.
D. The program will compile without error and will throw
              java.lang.NullPointerException when run
E. The program will compile without error and will run and terminate without any output.

Multiple Choice Question

QID: 
523

Consider the following code:

class A {
public void doA(int k) throws Exception {        // 0
for(int i=0; i< 10; i++) {
if(i == k) throw new Exception("Index of k is "+i);        // 1
}
}
public void doB(boolean f) {       // 2
if(f) {
doA(15); // 3
}
else return;
}
public static void main(String[] args) { // 4
A a = new A();
a.doB(args.length>0); // 5
}
}

Which of the following statements are correct?

Select 1 option

A. This will compile and run without any errors or exception.
B. This will compile if throws Exception is added at line //2
C. This will compile if throws Exception is added at line //4
D. This will compile if throws Exception is added at line //2 as well as //4
E. This will compile if line marked // 1 is enclosed in a try - catch block.

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)