• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you run this code? (I suppose you uncomment main() before you run it).
reply
    Bookmark Topic Watch Topic
  • New Topic