The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by Kishori Sharan on January 23, 2001 at 12:53 PM

In fact, this kind of assignment A a = new B() ; happens only in method argument passing where your method expects an object of class A and you pass it an object of its descendatant class, else we never need such kind of assigment when we already know we can use B b = new B() ; It was just his query and I tried to explain him the outcome. This also happens frequently in reading and writing data on network like
InputStream in = soc.getInputStream () ;
In the above case, you don't know for sure what is the class of object returned by getInputStream() except that it will be an object of one of sub-classes of InputStream.



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us