Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ghost Instances

 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Dan Temple
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get it ... thanks for the info!
Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic