|
UBBFriend: Email This Page to Someone! |
JavaRanch
Big Moose Saloon Programmer Certification Boone 1.1 Mock # 34 |
next newest topic | next oldest topic |
Author | Topic: Boone 1.1 Mock # 34 |
Eric
Barnhill ranch hand |
posted May 06, 2000 12:20 AM
One last ? on this mock Question 34: The method setBackground() defined for the Graphics class (...) b) takes an instance of class color (...) f) changes the background color for the associated Component object ------- these are the 2 right answers. First, I can't find a setBackground() method for the Graphics class, so presumably this means the setBackground() method of the Component class. But my question is, for b, is it accurate to say the method takes an "instance" of the Color class? Color.red (for ex.) doesn't look like anything is being instantiated to me, it looks like a static reference. Thank you very much Eric B. IP: Logged |
Herbert unregistered |
posted May 06, 2000 09:12 AM
As the question is put, b is quite correct. When you invoke setBackground(Color.red) for example, you indeed do not use any instance of the color class. However it is quite possible and legal to do something like this Color myColor = new Color(255,255,255); Here we are using an instance of the Color class that I created with the RGB values 255,255,255 (this is the color white, I guess). So the method can use the color constants as well as instances of the color class. IP: Logged |
maha
anna bartender |
posted May 07, 2000 02:31 PM
Eric, 1.The method setBackground() defined for the Graphics
class 2. takes an instance of class color I give to a simple example. See the foll Color class carefully. This is Sun's source code of Color class. I digged into the source code and extracted this class defn.
I have cut down the source code. See above what's really happening. The static class vars Color.black/Color.lightGray/Color.gray... are all static references to REAL PHISICAL OBJECTS(instances) in HEAP. Do you get the point now ?. an instance of a Color means an object of Color class. It is not related to instance/class members. I read this info from somewhere from some article. Since in Java , we are always talking about objects, and there is also a SPECIAL ansestor class Object, how can we pronounce these 2 words differently while talking from our mouth. . How can we diferentiate if you are talking the physical objects and the Class Object. While writing this is ok. We can put CAPITAL O for class Object and LOWERCASE 'o' for objects. But during conversation it is really difficult to distinguish these 2 words. So the Object orientad lang people invented one more word instance for referring to 'object' (real physical objects created from a class). So I think this story will help you what's actually happening here and the justification for your doubt. regds [This message has been edited by maha anna (edited May 07, 2000).] IP: Logged |
Eric
Barnhill ranch hand |
posted May 07, 2000 10:17 PM
Your story helps a lot. I did not think of the word "instance" that way before, I just saw it and thought "no static!". Now the question makes sense. Thanks to both of you Eric IP: Logged |
All times are MT (US) |
next newest topic | next oldest topic |
|
Powered by: Ultimate Bulletin Board, Version 5.44a
© Infopop Corporation
(formerly Madrona Park, Inc.), 1998 -
2000.