0% found this document useful (0 votes)
17 views1 page

Java Overloading

Overloading in Java allows a class to have multiple methods with the same name but different parameters, as demonstrated by a Base class method taking an int and a Derived class method taking a float, with the Derived object able to call the Base method through casting.

Uploaded by

leela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Java Overloading

Overloading in Java allows a class to have multiple methods with the same name but different parameters, as demonstrated by a Base class method taking an int and a Derived class method taking a float, with the Derived object able to call the Base method through casting.

Uploaded by

leela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Overloading in Java:

-----------------------------

class Base
{
public void method1(int i)
{
System.out.println("Inside Method1(int i) i= " + i);
}
}

class Derived extends Base


{
public void method1(float f)
{
System.out.println("Inside Method1(float f) f= " + f);
}
}

public class JavaOverload


{
public static void main(String[] args)
{
float f = 2.2f;
int i = 50;
Derived d1 = new Derived();

//d1.method1(i); //compile time error


((Base)d1).method1(i); //compiles correctly
}
}

You might also like