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

What is the use of Class.forName

20 Answers   HCL,


Is jvm a overhead?

0 Answers  


How substring() method of string class create memory leaks?

0 Answers  


What is a task?s priority?

1 Answers  


Should synchronization primitives be used on bean methods?

0 Answers  






To identify IDL language what mapping mechanism is used?

0 Answers  


hi friends, i have done my BE(CSE)at 2011 then i have joined one company before they asked me 50k so i paid but now they telling no project here so we r going to close like that so now i need any job i have good knowledge in core java and j2ee(jsp,servlet,jdbc) so if u know any job pl help me

0 Answers   Infosys,


what is the use of State Factories?

0 Answers  


What is difference RMI registry and OSAgent?

1 Answers  


what is an isolation level?

0 Answers  


Is the session factory thread safe?

0 Answers  


what is domain,give me some brief information about that?

1 Answers  


Categories