📜  java 虚拟覆盖 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:03.090000             🧑  作者: Mango

代码示例1
//Every non-static method in Java is a virtual function except for final and private methods. 
//The methods that cannot be used for the polymorphism is not considered as a virtual function.
//Java does not have a virtual keyword like C++,


class Vehicle{
void make(){
System.out.println("heavy duty");
}
}
public class Trucks extends Vehicle{
void make(){
System.out.println("Transport vehicle for heavy duty");
}
public static void main(String args[]){
Vehicle ob1 = new Trucks();
ob1.make();
}
}

//Output: Transport vehicle for heavy duty