hi waht is diffrence b/w this abstract method and overridding
Joined: Jun 24, 2004
//chack this code i want ot overridea swell as acces abstarct method same /time is it possible.--?
Edited by Corey McGlone: Added CODE Tags and Reformatted Code
[ June 29, 2004: Message edited by: Corey McGlone ] [ June 29, 2004: Message edited by: Corey McGlone ]
Joined: Dec 20, 2001
An abstract method is nothing more than a declaration. It simply states that any class that wishes to extend this class must override this method and provide its own implementation. Of course, on the other hand, you're free to override any non-static method, abstract or not. Abstract methods, however, must be overridden.
In addition, you can "invoke the abstract method" on a reference of the Superclass type. Take this example:
Why does this work? Well, the compiler knows that the reference variable s can't possibly reference an object of type Super. Why can't it? Super is defined as an abstract class - it can't be instantiated. Therefore, we know that whatever s references at runtime will be a subclass of Super and, because doIt() is an abstract method defined within Super, we know that whatever object s references will have to provide an implementation for that method. With all of that knowledge in hand, we can determine that the polymorphic call will execute safely.