17 November 2016

Java Interview questions part 2

8)What is method overriding?
If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method.
class Vehicle{
void run(){System.out.println(“Vehicle is running”); }}
class Bike2 extends Vehicle{
void run(){System.out.println(“Bike is running safely”);}
public static void main(String args[]){
Bike2 obj = new Bike2();
Bike is running safely

<<<< Click here for more >>>

No comments:

Post a Comment