I am a beginner in java. Here is my code
class Super{
public int a;
}
class sub extends Super{
int a = 10;
}
public class test{
public static void main(String args[]){
Super var = new sub();
System.out.println(var.a);//Here I want to print 10 , value of sub class
}
}
Is it possible and if it is then please tell me how? And I having some problem with the title of this question, so please suggest me an appropriate one as i had explained everything what i want in my code.
getAinsuband returnsuper.a. But in the end this is senseless in terms of realistic programming, because shadowing a variable is quite a bad programming practice and should be avoided.subdoes already know the variableaand shouldn´t declare it again.