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
Is it possible to write a regular expression to check if string is a number?
How to optimize the javac output?
What are the disadvantages of using inner classes?
Write a program in java to create a doubly linked list containing n nodes.
Who found java?
What happens when I use / and % with a negative numerator?
What is sleep method?
Is node a data type in java?
How do you sort data in java?
List out five keywords related to exception handling ?
Can a serialized object be transferred via network?
What are java threads?
What are static variables and functions?
Can you call one constructor from another if a class has multiple constructors?
What is the difference between inner class and nested class?