Here is the given code:
class Super {
protected int n;
Super(int n){
this.n=n;
}
public void print(){
System.out.println("n="+n);
}
}
class Sub {
Sub(int m){
Super.n=m;
}
}
class Test{
public static void main(String[] args){
Sub s= new Sub(10);
s.print();
}
}
I am getting these errors:
Main.java:19: error: non-static variable n cannot be referenced from a static context
Super.n=m;
...........^
Main.java:25: error: cannot find symbol
s.print();
Can someone please tell me why these errors occur?