Package Day8; public class Demo { public static void main (String [] args) { Son S = new new Son (); s.print (); } } class Father { int num1 = 10 ; int num2 = 20 is ; } class Son the extends father { int num2 = 30 ; // variables subclasses and superclasses best not to the same name, where for example using public void Print () { System.out.println (num1); // this class does not, call the parent class System.out.println (num2); // this class has, the principle of proximity System.out.println ( Super .num2); // Super can call the parent class System.out.println ( the this .num2); // the this the principle of proximity, both can call this class, you can call the parent class } }
operation result: