Inherited programming exercises
•
Java
Access the father class through son:
The code is as follows:
Father class:
Public class father {/ / instance variable and instance method int XX = 10; public void method() {system. Out. Println ("in father, method");}// Static variable and static method static int YY = 20; public static void sMethod(){ System.out.println("in father,static method"); }
}
Son class:
public class Son extends Father {
}
Test demo class:
Public class demo {public static void main (string [] args) {/ / access the instance member son Xiaoming = new son(); Xiaoming. Method(); system. Out. Println (Xiaoming. XX); / / access the static member son. Smethod(); system. Out. Println (son. YY);}}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码