Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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