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

Exp 10

Java2

Uploaded by

Gkhf
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)
19 views1 page

Exp 10

Java2

Uploaded by

Gkhf
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/ 1

Shree Vidyadhiraj Polytechnic, kumta Course : OOPs and Design With Java Course code: 20CS01P

_____________________________________________________________________________________

Exp 10: Write programs implement by inheritance concept.Create a class named


'Rectangle' with two data members 'length' and 'breadth' and two methods to print the
area and perimeter of the rectangle respectively.

class Rectangle {
private double length;
private double breadth;

public Rectangle(double length, double breadth) {


this.length = length;
this.breadth = breadth;
}

public void area() {


System.out.println(breadth * length);
}

public void perimeter() {


System.out.println(2 * (breadth + length));
}
}

class Square extends Rectangle {


public Square(double side) {
super(side, side);
}
}

public class test {


public static void main(String[] args) {
Rectangle rectangle = new Rectangle(10, 5);
Rectangle square = new Square(10);
rectangle.area();
rectangle.perimeter();
System.out.println();
square.area();
square.perimeter();
}
}

Output:

You might also like