hi Andres,
Is variable s1 in class B hiding s1 in class A
yes it is.
when you extend a class are you inheriting all non-private members
yes. except those which have hided any super class members.
how's the procedure to figure this out..
only instance methods are overriden.
Super s = new Sub();
s.m(); // will call sub's m IF it is overriden.
on the other hand feilds are shadowed. feilds are accessed using the reference variable type.
Super s = new Sub();// ref var is Super
s.aField; // will access S's aField
Sub s = new Sub();
Super sup = (Sup)s;
sup.aField; // will still access S's aField because the variable 'sup' reference type is Sup and not Sub.
In order to access Super's hidden feilds through Sub refernece, u can 'cast' to Super.
Sub s = new Sub();
int aField = ((Sup)s).aField;// now will access Sup's even if it is shadowed in Sub.
hope it helps.
[ June 07, 2003: Message edited by: G Nadeem ]