This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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 ]
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