I wrote this post, but it seems to have vanished, so i'll try again. Here is a brain teaser that I hope someon can solve. You cannot have instances of an abstract class. And yet InputStream and Graphics are both abstract classes. Once can get instances of these classes using the getInputStream() and getGraphics() methods respectively. So what gives? Thanks in advance Dan
You cannot directly instantiate an abstract class - that is, you cannot create an object which is an instance of that class but not any subclass. But you can create an instance of a subclass, which (by OO definitions) "is" an instance of the abstract class.
"I'm not back." - Bill Harding, Twister
Joined: Jul 10, 2001
That is what I suspected was going on (i.e. the instances are converted to instances of the respective abstract classes). But what classes (i.e. the subclasses) are being instantiated when the getGraphics() and getInputStream() are used? Thanks in advance Dan
The whole point is that you don't know what implementation you are using. That is the beauty of Object Oriented programming. Example (not the real classes used): Sun's virtual machine might pass you a com.sun.java.socket.SocketInputImpl when IBM's would pass you a com.ibm.core.Sockets.InputStream. Each one fits that vendor's separate JVM implementation. There is no need to know -- it just works. [This message has been edited by David Garland (edited August 21, 2001).]