Set 34

Descriptive Question

QID: 
532

Identify the exceptions that will be received when the code snippets on the left hand side are executed.

Multiple Choice Question

QID: 
531

What will the following program print when run?

public class TestClass{  
public static void main(String[] args){     
try{        
System.exit(0);     }     
finally{         
System.out.println("finally is always executed!");    
 }  } }

Select 1 option

A. It will print  "finally is always executed!" 
B. It will not compile as there is no catch block. 
C. It will not print anything. 
D. An exception will be thrown 
E. None of the above. 

Multiple Choice Question

QID: 
530

What will the following code print when compiled and run?

abstract class Calculator{   
abstract void calculate();   
public static void main(String[] args){      
System.out.println("calculating");      
Calculator x = null;     
 x.calculate();   } }

Select 1 option 

A. It will not compile. 
B. It will not print anything and will throw NullPointerException 
C. It will print calculating and then throw NullPointerException. 
D. It will print calculating and will throw NoSuchMethodError 
E. It will print calculating and will throw MethodNotImplementedException 

Multiple Choice Question

QID: 
529

Given the class

// Filename: Test.java 

public class Test{   
public static void main(String args[]){      
for(int i = 0; i< args.length; i++){         
System.out.print("  "+args[i]);      }   } } 

Now consider the following 3 options for running the program:

a: java Test 
b: java Test param1 
c: java Test param1 param2 

Which of the following statements are true?

Select 2 options 

A. The program will throw java.lang.ArrayIndexOutofBoundsException on option a. 
B. The program will throw java.lang.NullPointerException on option a. 
C. The program will print Test param1 on option b. 
D. It will print param1 param2 on option c. 
E. It will not print anything on option a.

Multiple Choice Question

QID: 
528

Consider the following method 

public float parseFloat( String s ){ 
  float f = 0.0f;   try{      
f = Float.valueOf( s ).floatValue();   
   return f ;   }  
 catch(NumberFormatException nfe){    
  f = Float.NaN ;     
 return f;   }   
finally{   
   f = 10.0f;     
 return f;   } }

What will it return if the method is called with the input "0.0" ?

Select 1 option 

A. It will not compile. 
B. It will return 10.0 
C. It will return Float.Nan 
D. It will return 0.0 
E. None of the above.

Pages

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) 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) (55) 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 (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) 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 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (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) 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)