| Author |
Abstract classes and Interfaces
|
Maduranga Liyanage
Ranch Hand
Joined: May 25, 2005
Posts: 124
|
|
Can I get some answers please?? 1) If an abstract class has more than one abstract method, when a subclass extends that class, does the sub class has to implement all the abstract methods? Can I extend an abstract class and not implement any abstract method? 2) If I implement an interface in my class, can I override a method in the interface? If I can, is there anyway I can get the original method implementation in my overriding class. Like the use of "super" in class methods to refer to the super class method? Thanks.. :-)
|
 |
Terry Rickson
Greenhorn
Joined: May 05, 2005
Posts: 22
|
|
|
I can help you out on the first question and that is you have to implement all the abstract methods from the abstract class if you are in the first concrete class otherwise if you have an abstract class extending another abstract class then the first concret class must implement all the abstract methods.
|
 |
Terry Rickson
Greenhorn
Joined: May 05, 2005
Posts: 22
|
|
For the second question - if you implement an interface you must override the methods in the interface anyway. Hope i've helped you in some way!
|
 |
Maduranga Liyanage
Ranch Hand
Joined: May 25, 2005
Posts: 124
|
|
|
So are all methods in Interfaces Abstract?
|
 |
Kedar Dravid
Ranch Hand
Joined: May 28, 2004
Posts: 333
|
|
|
All methods in an interface are implicitly public, abstract and non-static.
|
 |
Marcelo Ortega
Ranch Hand
Joined: May 31, 2005
Posts: 519
|
|
Yep, all of the methods declared in an interface are implicitly public abstract, and therefor must ALL be implemented in the first concrete class.
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
|
 |
 |
|
|
subject: Abstract classes and Interfaces
|
|
|