Package Day8; public class Polymorphyic { public static void main (String [] args) { Fruit F = new new Apple (); System.out.println (f.num); // member variable to see the left running, the output parent num, "10" Apple = A new new Apple (); a.print (); // member methods look to the right, the output subclass print (), "sub-class constructor" } } class Fruit { int NUM = 10 ; // parent class member variables public void Print () { System.out.println ( "parent class constructor" ); } } classApple the extends Fruit { int NUM = 20 is ; // child class member variables public void Print () { System.out.println ( "subclass constructor" ); } }
operation result:
10
Subclass Constructors
to sum up:
Member variable: Compile the left to see the parent class, run to see the left side of the parent class
Member methods: Compile the left to see the parent class, run to see the right sub-categories