Submitted by c-admin on Wed, 06/05/2019 - 04:19
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
Submitted by c-admin on Wed, 06/05/2019 - 04:13
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.
Submitted by c-admin on Wed, 06/05/2019 - 04:10
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.
Submitted by c-admin on Wed, 06/05/2019 - 04:07
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.
Submitted by c-admin on Wed, 06/05/2019 - 04:04
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