I suggest you try to understand encapsulation. Browse the group postings on Google, we recently answered a similar question.
ClassB b = new ClassB(); //works ClassA a = b; //works ClassA a = new ClassB(); //works But what if we add ClassC that extends ClassA, how can we keep track of the inheritance hierarchy? ClassA c = new ClassC(); When we read our code we can see the relationship. It make the world better and keeps world peace. On Dec 23, 7:50 pm, [email protected] wrote: > I'm trying to figure out why this doesn't accomplish the same thing > since B extends A anyhow. Newbie question. Thanks. > > B b = new B(); > > On Dec 23, 2009, at 12:47 PM, shivakant1 choudhary > <[email protected] > > > wrote: > > Class A{ > > } > > ClassB extends A{ > > } > > Class Main { > > public static void main(String s[])[ > > A a=new B(); > > //Here a is a reference variable > > } > > > On Wed, Dec 23, 2009 at 8:46 PM, Shashank Malhotra <[email protected] > > > wrote: > > I came across the following line: > > A reference variable of a superclass can be assigned a > > reference to any subclass derived from that superclass. > > what does that mean?? > > What is a reference variable?? > > -- > > To post to this group, send email to > > [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > For more options, visit this group > > athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en > > > -- > > To post to this group, send email to > > [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > For more options, visit this group > > athttp://groups.google.com/group/javaprogrammingwithpassion?hl=en > > -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
