If a subclass is having a data member with same name as superclass data member then inside subclass, subclass data member hides superclass data member.
class Sample{
int a = 5;
}
class SubSample extends Sample{
int a = 6;
void display(){
System.out.println("\n a="+a);
}
}
class InheritanaceDemo14{
public static void main(String[] args){
SubSample s = new SubSample();
s.display();
System.out.println("\n s.a="+s.a);
}
}
output:
a = 6
s.a = 6
class Sample{
int a = 5;
}
class SubSample extends Sample{
int a = 6;
void display(){
System.out.println("\n a="+a);
}
}
class InheritanaceDemo14{
public static void main(String[] args){
SubSample s = new SubSample();
s.display();
System.out.println("\n s.a="+s.a);
}
}
output:
a = 6
s.a = 6