Two Laptop Bag
The moose likes Beginning Java and the fly likes Abstract classes in Graphics class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract classes in Graphics class" Watch "Abstract classes in Graphics class" New topic

Abstract classes in Graphics class

Mark Mokris
Ranch Hand

Joined: May 08, 2002
Posts: 61
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

Joined: Jan 30, 2002
Posts: 3451
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

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Abstract classes in Graphics class
It's not a secret anymore!