File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Abstract class Graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class Graphics" Watch "Abstract class Graphics" New topic
Author

Abstract class Graphics

Ken Chen
Greenhorn

Joined: Jul 31, 2002
Posts: 10
The JDK document syas Graphics is a public ABSTRACT class. What does 'g' stands for in the following syntax, paint(Graphics g)? Reference to an instance? why if it does, since no instance for abstract classes.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
ken038,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.

In Java, a reference variable can refer to any object of the variables type or any subtype of that type. Therefore, the variable g in the paramater list can refer to any Graphics object (which can never really occur as the Graphics class is abstract) or any instance of a subclass of Graphics, such as a DebugGraphics object, which is not abstract.
I hope that helps,
Corey
[ July 31, 2002: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
satyendra gurjar
Greenhorn

Joined: Jul 31, 2002
Posts: 10
base class reference can hold the reference of the derived class object. Although Graphics is abstract class but its reference type can hold the reference of the object of its derived class.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
satyendra,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Stu Glassman
Ranch Hand

Joined: Jul 01, 2002
Posts: 91
ken, you are actually being passed an instance of a (non-abstract) subclass of Graphics. This subclass may be different for each implementation of the Java virtual machine, so continue using Graphics. If you'd like to see what the actual class is, call g.getClass().getName().
-Stu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class Graphics