Java-Method Overloading

Method Overloading

Method overriding occurs only when the names and the types signatures of the two methods are identical. If they are not, then the two methods are simply overloaded.

Program

1

Program Source

class Data {
    
    int data1;
    int data2;
    
    void dataValues()
    {
        System.out.println("data1 = "+data1);
        System.out.println("data2 = "+data2);
    }
}

class NewData extends Data {
    
    int data3;
    int data4;
    
    void dataValues(int x)
    {
        System.out.println("data3 = "+data3);
        System.out.println("data4 = "+data4);
    }
}

public class Javaapp {

    public static void main(String[] args) {
        
        NewData obj = new NewData();
        obj.data1 = 20;
        obj.data2 = 40;
        obj.data3 = 60;
        obj.data4 = 80;
        obj.dataValues();
        obj.dataValues(5);
    }
}

Leave a Comment