Find area Circle area = 78.5 Triangle area=3.60 Rectangle area=12
重写实现
当子类或子类具有与父类中声明的方法相同时,方法重写被定义为进程。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
classVehicle{ //defining a method voidrun(){System.out.println("Vehicle is moving");} } //Creating a child class classCar2extendsVehicle{ //defining the same method as in the parent class voidrun(){System.out.println("car is running safely");} publicstaticvoidmain(String args[]){ Car2obj=newCar2();//creating object obj.run();//calling method } }
输出:
1
Car is running safely
多态性问题
多态性在实施过程中相当具有挑战性。
多态性往往会降低代码的可读性。
多态性实时提出了一些严重的性能问题。
About this Post
This post is written by OwlllOvO, licensed under CC BY-NC 4.0.