Monday, 30 November 2015

Method Overriding Example - Java Program

package com.javaproficiency;


class Y {

void display(){
System.out.println(" Y is called");
}

}


public class X extends Y{

void display(){
System.out.println(" X is called");
}


public static void main(String[] args) {

    Y y = new Y();
    X x = new X();
    Y obj = new X();
   
    y.display();
    x.display();
    obj.display();
   
   

}

}



Output:

 Y is called

 X is called

 X is called

3 comments: