// 父类publicclassAnimal{voideat(){System.out.println("Animal is eating");}}// 子类publicclassDogextendsAnimal{voidbark(){System.out.println("Dog is barking");}}
// 方法重载(编译时多态)publicclassCalculator{intadd(int a,int b){return a + b;}doubleadd(double a,double b){return a + b;}}// 方法重写(运行时多态)publicclassAnimal{voidmakeSound(){System.out.println("Animal makes a sound");}}publicclassDogextendsAnimal{voidmakeSound(){System.out.println("Dog barks");}}