0% found this document useful (0 votes)
20 views

Exp 4

The document contains examples of constructor overloading and method overloading in Java. It defines two classes - one with overloaded constructors that take different parameters and one with overloaded methods that take different parameters. The examples demonstrate calling the overloaded constructors and methods and outputting the results.

Uploaded by

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

Exp 4

The document contains examples of constructor overloading and method overloading in Java. It defines two classes - one with overloaded constructors that take different parameters and one with overloaded methods that take different parameters. The examples demonstrate calling the overloaded constructors and methods and outputting the results.

Uploaded by

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

EXPERIMENT - 4

a) Constructor Overloading
AIM: To write a JAVA program to implement constructor overloading
SOURCE-CODE:
class A
{
int l,b;
A()
{
l=10;
b=20;
}
A(int u,int v)
{
l=u;
b=v;
}
int area()
{
return l*b;
}
}
class overconstructdemo
{
public static void main(String args[])
{
A a1=new A();
int r1=a1.area();
System.out.println("The area is: "+r1);
A a2=new A(30,40);
int r2=a2.area();
System.out.println("The area is: "+r2);
}
}
OUT-PUT:
The area is: 200
The area is: 1200
b) Method Overloading
AIM: To write a JAVA program implement method overloading
SOURCE-CODE:
class A
{
int l=10,b=20;
int area()
{
return l*b;
}

WWW.KVRSOFTWARES.BLOGSPOT.COM
int area(int l,int b)
{
return l*b;
}
}
class overmethoddemo
{
public static void main(String args[])
{
A a1=new A();
int r1=a1.area();
System.out.println("The area is: "+r1);
int r2=a1.area(5,20);
System.out.println("The area is: "+r2);
}
}
OUT-PUT:
The area is: 200
The area is: 100

WWW.KVRSOFTWARES.BLOGSPOT.COM

You might also like