0% found this document useful (0 votes)
14 views6 pages

EXP 4 - Java

The document presents a programming experiment focused on constructor and method overloading in Java. It includes two classes, 'Room' for demonstrating constructor overloading and 'Shape' for method overloading to calculate areas of different shapes. The code executes successfully, showcasing the functionality of both concepts.

Uploaded by

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

EXP 4 - Java

The document presents a programming experiment focused on constructor and method overloading in Java. It includes two classes, 'Room' for demonstrating constructor overloading and 'Shape' for method overloading to calculate areas of different shapes. The code executes successfully, showcasing the functionality of both concepts.

Uploaded by

Shreya Ranjane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment No.

Roll No:124A8092

Aim: Program on constructor and method overloading

a. WAP for constructor overloading.

class Room

double len,breadth;

Room()

{
len=0;

breadth=0;

Room(double l,double b)

len=l;

breadth=b;

Room(double x)

len=breadth=x;

Room(int l)

len=l;

breadth=17.5;

double area()

double AREA;

AREA=len*breadth;

[Link]("Area of room is :"+AREA);

return AREA;

public static void main(String[]args)


{

Room R1=new Room();

[Link]();

Room R2=new Room(20.5,10.5);

[Link]();

Room R3=new Room(20.4);

[Link]();

Room R4=new Room(12);

[Link]();

b. WAP on method overloading to calculate area of circle, rectangle and triangle.

class Shape

void area(double side)

double square;

square = side * side;

[Link]("Area of square is:" + square);

void area(int len, int breadth)


{ int rectangle;

rectangle = len * breadth;

[Link]("Area of rectangle is:" + rectangle);

void area(int radius)

double circle;

circle = 3.14 * radius * radius;

[Link]("Area of circle is:" + circle);

} public static void main(String[] args)

Shape S1 = new Shape();

[Link](5.6);

[Link](11, 12);

[Link](7);

}
Output:

Conclusion:
The code is executed successfully.

You might also like