The inherited member x is int. However, I am redeclaring it as String while subclassing. Is this allowed?
Also, if I make line 1 as public, I am able to change line 2 as private. Compiler doesn't complain that the member has become less accessible. Is that ok as well?
Variables are not inherited, they are hidden. It means the there are two varaibles in sub class, one is variable x present in Class A and other is x in Class B. So here as u r accessing x, the JVM will first search if that variable is present in ur class, if the varaible is defined in ur class, if not it searches its super class and finally comes up with the result. I hope thats ok with u
Hi, Members are not overriding. If you declared the member in subclass i.e,. available in superclass that memeber will be shadowing. This is also called as instance memeber hiding.
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
1)Though it is shadowing can i say it is possible to access the superclass variable using the Fully qualified Name. (i.e)SuperClassName.variablename
If it is static memebers it is possible. just walk through the below code. If any doubt post again.
Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>