class A{
some variables;
public void a()throws Excepion1,Exception2{....}
}
class B extends A{
variables...
public void a()throws E2,E3{.....}
}
Qns:
here override of methods occurs or not,ore else wil give
any compilation error or run properly..plz tell me briefly
whts happening with the above codes....

Answers were Sorted based on User's Feedback



class A{ some variables; public void a()throws Excepion1,Exception2{....} } class B ex..

Answer / dipesh

this will throw complie error b'coz u r overirding the
method & u overirdng method cant throw exceptions which is
not being thrown by overirded method hwevr ovrindng method
can throw runtime exceptions

Is This Answer Correct ?    10 Yes 0 No

class A{ some variables; public void a()throws Excepion1,Exception2{....} } class B ex..

Answer / anjan singh

while overriding, you must keep in mind that the exception
being thrown by overriding method(method in subclass)
should not throw a broader exception than what is already
thrown by method in super class. one exception is that, you
can always throw RuntimeException from method in subclass.

Is This Answer Correct ?    1 Yes 0 No

class A{ some variables; public void a()throws Excepion1,Exception2{....} } class B ex..

Answer / jeevan

It is a good programming practice to have only a sub set of
checked exceptions classes from the throws clause of the
inherited method of the superclass.


Here in the above example E2,E3 exception are not a subset
of the exception classes of the inherited method

Is This Answer Correct ?    2 Yes 2 No

class A{ some variables; public void a()throws Excepion1,Exception2{....} } class B ex..

Answer / sunita

Overriding methods cannot change the signature of the
overridden method. but runtime exception r not present in
signature so u can only add the runtime exception in
overriden method.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More Core Java Interview Questions

How do you reverse a list?

0 Answers  


what is difference between abstract factory and factory design patterns?

0 Answers  


where u use Abstraction and Interface in real time

3 Answers   Sonata,


When finalize method is called?

3 Answers  


What is a parent class in java?

0 Answers  






Why set is used in java?

0 Answers  


Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.

5 Answers  


Can a singleton class be inherited?

0 Answers  


What is the purpose of methodology?

0 Answers  


all are saying java doesn't support multiple inheritance but by default Object class is super class for all the user defined classes and we can extend atmost one class so each class can extend more than one class so java supports multiple inheritance?i am confused with this,pls any one explain me.

4 Answers  


How many arguments can be passed to main ()?

0 Answers  


How you can force the garbage collection?

0 Answers  


Categories