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
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 |
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 |
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 |
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 |
After compilation of java program we'll get .class code. If it's generated in OS Windows XP will it work on OS Linux? If yes why? If no why?
Define a package.
Why is java so popular?
What is the difference between the >> and >>> operators?
how to create multithreaded program? : Java thread
how to use this key word in java programming?
what is singlton class?where it is use in real time senario.
What is null in java?
What is final?
Can constructor be inherited?
how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion
What is an error in java?