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
Can two objects have same hashcode?
What is the disadvantage of synchronization?
enlist some features of jdk.
What is this () in java?
What is javac in java?
Which non-unicode letter characters may be used as the first character of an identifier?
How do I remove a character from a string in java?
Should database connections be singleton?
Is zero a positive integer?
Can we use string in the switch case?
What is a package in java? List down various advantages of packages.
What is run time allocation?
What about interthread communication and how it takes place in java?
Is hashset sorted in java?
How many decimal digits is 64 bit?