File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hi waht is diffrence b/w this abstract method and overridding

 
giribabu venugopal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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 ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you run this code? (I suppose you uncomment main() before you run it).
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic