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
how to handle exceptions in ejb?
How does enum work in java?
List some important features of java 10 release?
What is function and its uses?
What is equlas() and hashcode() contract in java? Where does it used?
What is ctrl m character?
What are the two ways in which thread can be created?
What are the different data types in java?
What are the basic interfaces of java collections framework?
What is instance example?
Write a java program to check if a number is prime or not?
Which data type is class in java?
List implementations of list interface?
If I only change the return type, does the method become overloaded?
What are static methods?