Q:
If sub class data member is hiding super class data member then how to access super class data member inside sub class methods?
Answer
use super keyword.
super keyword points immediate super class.
Class Sample {
int a =23;
}
Class Sub extends Sample {
String a = "bablu";
void show() {
System.out.println(a); //bablu
System. out. println(this.a); //bablu
System. out.println(super.a); //23
}
}
Class Demo {
Public static void main(string[] args) {
sub s = new Sub();
s.show();
}
}
View answer
Workspace
Report Error
Discuss