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
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
What is the length of a string?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread
os is developed in c no java is more secured then c na why dont the os developed is developed using java
Can inner class final?
Is java 9 released?
What is tree in java?
I want to print “hello” even before main is executed. How will you acheive that?
What does compareto () do in java?
How do you trim a space in java?
What is the difference between post and put?
What is * argv?
What is java in layman terms?
Which methods are used during serialization and deserialization process?
Give me an example of array and linked list? Where they can be used?