• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ghost Instances

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get it ... thanks for the info!
Dan
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic