Tuesday, 14 July 2009

Java Certification Question 0034

What will happen when you attempt to compile and run the following code?

import java.io.*;

class ExBase{
abstract public void martley(){
}
}

public class MyEx extends ExBase{

public static void main(String argv[]){
DataInputStream fi = new DataInputStream(System.in);
try{
fi.readChar();
}catch(IOException e){
System.exit(0);
}
finally {System.out.println("Doing finally");}
}
}

1) Compile time error
2) It will run, wait for a key press and then exit
3) It will run, wait for a keypress, print "Doing finally" then exit
4) At run and immediately exit



Answer :
1) Compile time error
It wil produce an error like "Abstract and native method can't have a body. This is typical of the more misleading question where you might think it is asking you about the circumstances under which the finally clause runs, but actually it is about something else.

No comments: