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 / bhanu
hi,
Keep the whole code in a class
Ex:
class Sample
{
.....
..... //the above code
.....
.....
}
Now it will not give any error while compilation.
It is the concept of static nested classed
Thank you
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can a constructor be made final?
Can we pass null as argument in java?
How do you break a loop?
Why volatile is used in java?
Name some OOPS Concepts in Java?
What is an example of a constant variable?
When can you say a graph to be a tree?
How to instantiate member inner class?
What are the object and class classes used for?
What is the purpose of the return statement?
How many types of java are there?
What is the difference between an if statement and a switch statement?
How many arguments can be passed to main ()?
What is class forname?
Does java map allow duplicates?