Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract classes in Graphics class

 
Mark Mokris
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I look at the method signatures in the Java API for the Graphics class I see the drawing methods like drawString( ) and drawRect( ) are declared as abtract void.
The thought occurred to me. How can they be abstract? If they are abstract where does their functionality come from?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
They come from the native code implementation that is supplied with the java runtime for your hardware. So when a Graphics object is passed in to your paint method, for example, it is a concrete platform-specific subclass.
Hope this clears it up,
Michael Morris
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: Considering such a class heirarchy, the implementation of the methods could also be in some subclass of the parent abstract class - it doesn't have to be in machine specific code.
You might want to take a look at The "How my Dog learned Polymorphism" Story of The JavaRanch Campfire Stories and The Managing Inheritance Section of Sun's Java Tutorial.
If you ever want to find out what class an object actually is (not just the identifier's type)...
All objects in Java inherit the getClass() method from java.lang.Object. Use toString() on the returned Class object and find out.You could similarly invoke the getName() method of the Class object.
Good Luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic