Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java virtual override

//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

Source by www.edureka.co #
 
PREVIOUS NEXT
Tagged: #java #virtual #override
ADD COMMENT
Topic
Name
1+2 =