Sunday, 18 December 2022

Overloading Develop a program which show one method (as you want ) is overloaded (method overloading)

OVERLOADING


class Student {
    String name;
    int age;

    public void displayInfo(String name) {
        System.out.println(name);
    }

    public void displayInfo(int age) {
        System.out.println(age);
    }

    public void displayInfo(String name, int age) {
        System.out.println(name);
        System.out.println(age);
    }

    public static void main(String args[]) {
        Student avi = new Student();
        avi.displayInfo("avinash");
        avi.displayInfo(22);
    }
}



output: 

avinash

22

 

No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...