method overloading java program

Here java program to implement method overloading. In method overloading, there are n methods with same name but with different parameter in same class. And in OOP’s it is also known as compile-time polymorphism.

Method overloading java program :-

Source Code:

// method overloading java program

class Student
{   
    // first method 
    void print(String name)
    {
        System.out.println("This is "+name);
    }
    
    // second method
    void print(String fName, String lName)
    {
        System.out.println("This is "+fName+lName);
    }
}

class Main
{
    public static void main(String s[]) 
    {
        Student st = new Student();
        st.print("Tech");
        st.print("Tech", "Almirah");
    }
}

Output:

This is Tech
This is TechAlmirah

Recommended Post