Will it be called overriding if I do not change the
parameters or return type, instead throw a different
exception in the method signature.

Answers were Sorted based on User's Feedback



Will it be called overriding if I do not change the parameters or return type, instead throw a dif..

Answer / prakash

An Overridden method can throw lesser exceptions or no
exception and any new Runtime exceptions

An overridden method can't throw any new checked exception
or broader exceptions than its base class method.

Is This Answer Correct ?    6 Yes 0 No

Will it be called overriding if I do not change the parameters or return type, instead throw a dif..

Answer / surendra

the overriding method can throw narrow exceptions than overridden exception

Is This Answer Correct ?    3 Yes 0 No

Will it be called overriding if I do not change the parameters or return type, instead throw a dif..

Answer / siva

public class MyOverriding {
int add(int a, int b)throws Exception{ //TRUE
return a+b;
}
}
class SubClass extends MyOverriding {
int add(int a, int b)throws NullPointerException{
return a+b;
}
}

//BELOW CODE IS GETTING COMPILER ERROR
public class MyOverriding {
int add(int a, int b)throws NullPointerException{
return a+b;
}
}
class SubClass extends MyOverriding {
int add(int a, int b)throws Exception{
return a+b;
}
}

Is This Answer Correct ?    2 Yes 0 No

Will it be called overriding if I do not change the parameters or return type, instead throw a dif..

Answer / contessa

yes, you will be overriding to throw a different exception

Is This Answer Correct ?    0 Yes 5 No

Post New Answer

More Advanced Java Interview Questions

Which container method is used to cause a container to be laid out and redisplayed?

0 Answers  


When is the best time to validate input?

0 Answers  


What’s jboss cache in short?

0 Answers  


What is ioc concept?

0 Answers  


How to deploy Jar, War files in J2EE?

0 Answers   HCL,


Why DOM Parser would take more Memory than SAX parser while they are parsing?

3 Answers   OnMobile,


life cycle of an applet?

3 Answers  


What is thread deadlock? How to resolve thread deadlock?

3 Answers  


what is an isolation level?

0 Answers  


What is the use of Semaphore?

3 Answers  


What are transaction attributes?

0 Answers  


What is the use of Class.forName

20 Answers   HCL,


Categories