1. Create MyTest7
com.example.jvm.bytecode Package; Import java.util.Date; public MyTest7 class { public static void main (String [] args) { Animal Animal Animal new new = (); Animal Dog Dog new new = (); animal.test ( "Hello"); dog.test (new new a Date ()); } } // overload existing methods, there are a subclass of Dog method of rewriting class Animal { public void Test (String STR) { the System. Out.println ( "Animal Test"); } public void Test (a Date DATE) { System.out.println ( "Animal DATE"); } } class Dog the extends Animal { @Override public void Test (String STR) { System.out.println ( "Test Dog" ); } @Override public void test(Date date) { System.out.println("dog date"); } }
Output:
animal test
dog date