11. static class A {
12. void process() throws Exception { throw new Exception();
}
13. }
14. static class B extends A {
15. void process() { System.out.println(”B”); }
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }
What is the result?
1 B
2 The code runs with no output.
3 Compilation fails because of an error in
line 12.
4 Compilation fails because of an error in
line 15.

Answer Posted / vasanth g

Here we are directly process method of class b.
so ans B that is 1st option....
consider this

static classA {
void process() throws Exception { throw new Exception(); }
}
static class B extends A {
void process() { System.out.println(�B �); }
}
public static void main(String[] args) {
A a=new B();
a.process();
}

in this program compilation fails at a.process
because compiler doen't know that reference a point on class
B where there's no exception. a is of A type and A's method
throws exception that isn't handled .a.process() enclosed in
try catch block.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if I remove static from main method?

512


What is the difference between length and length() method in java?

635


Is empty set an element of empty set?

591


what is daemon thread and which method is used to create the daemon thread? : Java thread

518


If goto and const is reserve words than why it is not work in java?

1496






Can a class be protected in java?

491


Difference between overriding and overloading in java?

566


Why java is object oriented?

579


What is jrmp?

542


Can list be final in java?

481


Can a constructor call another constructor?

556


What is indexof?

535


What is starvation?

672


How is abstraction implemented in java ?

532


What is scope & storage allocation of global and extern variables? Explain with an example

573