Hi All,
Reading about private
here.It says that you can't use a private variable declared in your superclass in your subclass.I wrote a code :
class ParentClass{
private String name;
public ParentClass(){
this.name="sam";
}
public String getName(){
return name;
}
}
public class ChildClass extends ParentClass{
public String getFullName(){
return getName()+" de Souza";
}
public static void main(String[] args){
ChildClass cc=new ChildClass();
System.out.println(cc.getFullName());
}
}
Looking at the above code I can see that the ChildClass
inherits the private variable and
uses it to return the full name.
Can somebody please clear my doubt?
Regards
james