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
How can you make a class serializable in java?
What are java packages? What's the significance of packages?
Is list thread safe in java?
What is double in java?
How are the elements of a gridbaglayout organized in java programming?
Difference between comparator and comparable in java?
What is the difference between sleep and wait in java?
Can we have any code between try and catch blocks?
What is the purpose of skeleton and stub?
What are the two categories of data types in the java programming language?
What is the difference between compare and compareto in java?
What are classloaders?
What are the two types of java programming?
Difference between string, stringbuffer and stringbuilder?
Why pass by reference is not possible in java?