What is the output of the following program code?
public class Test{
public static void main(String args[]){
try{
int i;
return;
}
catch(Exception e){
System.out.print("inCatchBlock");
}
finally{
System.out.println("inFinallyBlock");
}
}
}
What is the output of the following program code?
public class Test{
public static void main(String args[]){
try{
int i;
return;
}
catch(Exception e){
System.out.print("inCatchBlock");
}
finally{
System.out.println("inFinallyBlock");
}
}
}
What will be the result after the class Test execution?
class A{
public void doA(){
B b = new B();
b.dobB();
System.out.print("doA");
}
}
class B{
public void dobB(){
C c = new C();
c.doC();
System.out.print("doB");
}
}
class C{
public void doC(){
if(true)
throw new NullPointerException();
System.out.print("doC");
}
}
public class Test{
public static void main(String args[]){
try{
A a = new A();
a.doA();
}catch(Exception ex){
System.out.print("error");
}
}
}
What will be the result after the class Test execution?
class A{
public void doA(){
B b = new B();
b.dobB();
System.out.print("doA");
}
}
class B{
public void dobB(){
C c = new C();
c.doC();
System.out.print("doB");
}
}
class C{
public void doC(){
if(true)
throw new NullPointerException();
System.out.print("doC");
}
}
public class Test{
public static void main(String args[]){
try{
A a = new A();
a.doA();
}catch(Exception ex){
System.out.print("error");
}
}
}
public class Test{
public static void main(String args[]){
try{
int a = Integer.parseInt("four");
}
}
}
Which exception could be handled by the catch block for above?
public class Test{
public static void main(String args[]){
try{
int a = Integer.parseInt("four");
}
}
}
Which exception could be handled by the catch block for above?
Which keyword is used to explicitly throw an exception?
Which keyword is used to explicitly throw an exception?
What will be the output of the following piece of code:
class Person{
public void talk() {}
}
public class Test{
public static void main(String args[]){
Person p = null;
try{
p.talk();
}
catch(NullPointerException e){
System.out.print("There is a NullPointerException. ");
}
catch(Exception e){
System.out.print("There is an Exception. ");
}
System.out.print("Everything went fine. ");
}
}
What will be the output of the following piece of code:
class Person{
public void talk() {}
}
public class Test{
public static void main(String args[]){
Person p = null;
try{
p.talk();
}
catch(NullPointerException e){
System.out.print("There is a NullPointerException. ");
}
catch(Exception e){
System.out.print("There is an Exception. ");
}
System.out.print("Everything went fine. ");
}
}
Which exception is thrown when divide by zero statement executes?
Which exception is thrown when divide by zero statement executes?
Which of the following blocks execute compulsorily whether exception is caught or not.
Which of the following blocks execute compulsorily whether exception is caught or not.
Which exception is thrown when an array element is accessed beyond the array size?
Which exception is thrown when an array element is accessed beyond the array size?
Which of the below statement is/are true about Error?
A. An Error is a subclass of Throwable.
B. An Error is a subclass of Exception.
C. Error indicates serious problems that a reasonable application should not try to catch.
D. An Error is a subclass of IOException.
Which of the below statement is/are true about Error?
A. An Error is a subclass of Throwable.
B. An Error is a subclass of Exception.
C. Error indicates serious problems that a reasonable application should not try to catch.
D. An Error is a subclass of IOException.
In which of the following package Exception class exist?
In which of the following package Exception class exist?
What happen in case of multiple catch blocks?
What happen in case of multiple catch blocks?
What will be the output?
class MyClass{
public String test(){
try{
System.out.print("One");
return "";
}
finally{
System.out.print("Two");
}
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.test();
}
}
What will be the output?
class MyClass{
public String test(){
try{
System.out.print("One");
return "";
}
finally{
System.out.print("Two");
}
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.test();
}
}
try{
File f = new File("a.txt");
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt ?
try{
File f = new File("a.txt");
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt ?
Which keyword is used to specify the exception thrown by method?
Which keyword is used to specify the exception thrown by method?
Predict the output:
public class Test{
public static void main(String args[]){
try{
String arr[] = new String[10];
arr = null;
arr[0] = "one";
System.out.print(arr[0]);
}catch(Exception ex){
System.out.print("exception");
}catch(NullPointerException nex){
System.out.print("null pointer exception");
}
}
}
Predict the output:
public class Test{
public static void main(String args[]){
try{
String arr[] = new String[10];
arr = null;
arr[0] = "one";
System.out.print(arr[0]);
}catch(Exception ex){
System.out.print("exception");
}catch(NullPointerException nex){
System.out.print("null pointer exception");
}
}
}
What will be the result of executing the following code?
public class Test{
public void divide(int a, int b){
try{
int c = a / b;
}catch(Exception e){
System.out.print("Exception ");
}finally{
System.out.println("Finally");
}
public static void main(String args[]){
Test t = new Test();
t.divide(0,3);
}
}
What will be the result of executing the following code?
public class Test{
public void divide(int a, int b){
try{
int c = a / b;
}catch(Exception e){
System.out.print("Exception ");
}finally{
System.out.println("Finally");
}
public static void main(String args[]){
Test t = new Test();
t.divide(0,3);
}
}
Given the following piece of code:
class SalaryCalculationException extends Exception{}
class Person{
public void calculateSalary() throws SalaryCalculationException{
//...
throw new SalaryCalculationException();
//...
}
}
class Company{
public void paySalaries(){
new Person().calculateSalary();
}
}
Which of the following statements is correct?
1. This code will compile without any problems.
2. This code will compile if in method paySalaries() we return a boolean in stead of void.
3. This code will compile if we add a try-catch block in paySalaries().
4. This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries().
Given the following piece of code:
class SalaryCalculationException extends Exception{}
class Person{
public void calculateSalary() throws SalaryCalculationException{
//...
throw new SalaryCalculationException();
//...
}
}
class Company{
public void paySalaries(){
new Person().calculateSalary();
}
}
Which of the following statements is correct?
1. This code will compile without any problems.
2. This code will compile if in method paySalaries() we return a boolean in stead of void.
3. This code will compile if we add a try-catch block in paySalaries().
4. This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries().
Determine output of the following program code?
public class Test{
public static void main(String args[]){
int i;
try{
i = calculate();
System.out.println(i);
}catch(Exception e){
System.out.println("Error occured");
}
}
static int calculate(){
return (7/2);
}
}
Determine output of the following program code?
public class Test{
public static void main(String args[]){
int i;
try{
i = calculate();
System.out.println(i);
}catch(Exception e){
System.out.println("Error occured");
}
}
static int calculate(){
return (7/2);
}
}
What will be the result after compiling this code?
class SuperClass{
public int doIt(String str, Integer... data)throws Exception{
String signature = "(String, Integer[])";
System.out.println(str + " " + signature);
return 1;
}
}
public class Test extends SuperClass{
public int doIt(String str, Integer... data){
String signature = "(String, Integer[])";
System.out.println("Overridden: " + str + " " +signature);
return 0;
}
public static void main(String... args){
SuperClass sb = new Test();
sb.doIt("hello", 3);
}
}
What will be the result after compiling this code?
class SuperClass{
public int doIt(String str, Integer... data)throws Exception{
String signature = "(String, Integer[])";
System.out.println(str + " " + signature);
return 1;
}
}
public class Test extends SuperClass{
public int doIt(String str, Integer... data){
String signature = "(String, Integer[])";
System.out.println("Overridden: " + str + " " +signature);
return 0;
}
public static void main(String... args){
SuperClass sb = new Test();
sb.doIt("hello", 3);
}
}
What will be the result if NullPointerException occurs at line 2?
1. try{
2.
3. }
4. catch(NullPointerException ne){
5. System.out.print("1 ");
6. }
7. catch(RuntimeException re){
8. System.out.print("2 ");
9. }
10. finally{
11. System.out.print("3");
12. }
What will be the result if NullPointerException occurs at line 2?
1. try{
2.
3. }
4. catch(NullPointerException ne){
5. System.out.print("1 ");
6. }
7. catch(RuntimeException re){
8. System.out.print("2 ");
9. }
10. finally{
11. System.out.print("3");
12. }
Exception generated in try block is caught in ........... block.
Exception generated in try block is caught in ........... block.
Given the code. What is the result when this program is executed?
public class Test{
static int x[];
static{
x[0] = 1;
}
public static void main(String args[]){
}
}
Given the code. What is the result when this program is executed?
public class Test{
static int x[];
static{
x[0] = 1;
}
public static void main(String args[]){
}
}
The class at the top of exception class hierarchy is .................
The class at the top of exception class hierarchy is .................
What is the output for the below code ?
import java.io.FileNotFoundException;
class A{
public void printName() throws FileNotFoundException{
System.out.println("Value-A");
}
}
class B extends A{
public void printName() throws NullPointerException{
System.out.println("Name-B");
}
}
public class Test{
public static void main (String[] args) throws Exception{
A a = new B();
a.printName();
}
}
What is the output for the below code ?
import java.io.FileNotFoundException;
class A{
public void printName() throws FileNotFoundException{
System.out.println("Value-A");
}
}
class B extends A{
public void printName() throws NullPointerException{
System.out.println("Name-B");
}
}
public class Test{
public static void main (String[] args) throws Exception{
A a = new B();
a.printName();
}
}