© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Flow Control and Exception Handling ▼

Java Interview Questions On Flow Control and Exception Handling

20. Explain Exception in overriding methods?

Answer:

In an inheritance hierarchy when you extend a class and trying to override a method declared as throwing a checked exception, then the Java follows certain rules given below.

  • l The overriding method can throw same checked exception as the original method.
  • l The overriding method may not throw any checked exceptions.
  • l The overriding method can throw subclasses of the original method in the parent class.
  • l The overriding method cannot throw more checked exceptions than the original method.

21. What is the result when you compile and run the following code?
int i = 100;
switch (i) {
case 100:
System.out.println(i);
case 200:
System.out.println(i);
case 300:
System.out.println(i);
}
[a] Nothing is printed
[b] Compile time error
[c] The values 100,100,100 printed
[d] Only 100 is printed

Answer
[c] The values 100,100,100 printed

22. What is the result when you compile and run the following code?
int i = 100;
switch (i) {
case 100:
System.out.println(i);
break;
case 200:
System.out.println(i);
break;
case 300:
System.out.println(i);
break;
}
[a] Nothing is printed
[b] Compile time error
[c] The values 100,200,300 printed
[d] Only 100 is printed

Answer

[d] Only 100 is printed

23. What is the result when you compile and run the following code?
boolean b = true;
if (b) {
System.out.println("True");
} else {
System.out.println("False");
}
[a] Nothing is printed
[b] True is printed
[c] False is printed
[d] Compile time error

Answer

[b] True is printed
Previous Next
1 2 3 4 5 6 7 8 9
SLogix Student Projects
bottom