Prepare for your Next Interview
This is a discussion on which 1 to use within the Java forums, part of the Software Development category; if i have a class that can extend abs class n implement interface...and it doesnt have to achieve inheritance ,doesnt hav to extend any other class then which 1 ...
|
|||
|
if i have a class that can extend abs class n implement interface...and it doesnt have to achieve inheritance ,doesnt hav to extend any other class then which 1 should i use between extending a abs class with abs method or implementing interface with abs method.?/
![]() pls ans |
| Sponsored Links |
|
|||
|
Re: which 1 to use
not sure if the question is clear enough... but i will try:
if you implement the interface - you will have to rewrite the method/s. if you exted - u can call existing code without writing anything. If I understand the question correctly - "doesnt have to achieve inheritance " - you probably mean that we dont have to use any existing method of the original class. therefore - I would go with implementing the interface. |
|
|||
|
I am not sure whether I understood your question or not!!.
But I want to share with you something. If you want to make a class or method that can not be extended by other classes. then declare that class or method as final. then that class or method cannot be extended by other class |
|
|||
|
Re: which 1 to use
sorry frens.i think u didnt get my question.I am explaining again..
I got this question in an interview. ![]() Which 1 i will choose if given a choice between extending an abstract class and implementing a interface ..which 1 I should opt. NB:Class which ll either extnd or implement doesnt have any other requirements. Pls ans i hope its now clear... Thanks 4 ur replies. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|