0% found this document useful (0 votes)
48 views3 pages

Practical 10

The document contains code for two Java classes that demonstrate using single and multiple constructors. The first class, Rectangle, defines a single constructor that takes length and width parameters and calculates the area. The second class, perimeter, defines two constructors - one default and one that takes length and breadth, and includes a method to calculate perimeter. The main method creates instances of each class and outputs the calculated values.

Uploaded by

Nikhil Chaugule
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)
48 views3 pages

Practical 10

The document contains code for two Java classes that demonstrate using single and multiple constructors. The first class, Rectangle, defines a single constructor that takes length and width parameters and calculates the area. The second class, perimeter, defines two constructors - one default and one that takes length and breadth, and includes a method to calculate perimeter. The main method creates instances of each class and outputs the calculated values.

Uploaded by

Nikhil Chaugule
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
You are on page 1/ 3

Roll No: 51

Practical No 10
Single Constructor:
class Rectangle

int length,width;

Rectangle(int x,int y)

length = x;

width = y;

int recArea()

return(length*width);

class pr10_1

public static void main(String[] args)

Rectangle rect1 = new Rectangle(15,10);

int area = rect1.recArea();

System.out.println("Area = "+area);

Output:

Area = 150
Multiple Constructor:
class perimeter

int length,breadth;

perimeter()

length = 0;

breadth = 0;

perimeter(int x, int y)

length = x;

breadth = y;

void cal_perimeter()

int peri;

peri = 2*(length+breadth);

System.out.println("\n The perimeter of rectangle is "+peri);

class pr10_2

public static void main(String[] args)

perimeter p1 = new perimeter();

perimeter p2 = new perimeter(10,30);

p1.cal_perimeter();

p2.cal_perimeter();

}
}

Output:

The perimeter of rectangle is 0

The perimeter of rectangle is 80

You might also like