create a class named rectangle with the following description instance variable: int length-to store the length of the rectangle,int breadth: to store the breadth of the rectangle.member method:rectangle(int x,int y)-constructor to initialize the data members int rectArea() to calculate the area of the rectangle.write main method to create an object of the class and call the above member methods
Answers
Answered by
8
Answer:
"class rectangle
{
int length, breadth; // instance variables, can also be replace with x, y to get parameterized constructor: rectangle(int x, int y) . .
rectangle () {
length = 2;
breadth = 2;
float rect.Area () {
return length * breadth;
}
}
public class main {
public static void main (String args[]) {
rectangle obj = new rectangle (); // create new object
float rect.Area;
rect.Area = obj.rect.Area ();
system.out.println (“Area is” +rect.Area); // prints area of the rectangle
}
}
"
Explanation:
Similar questions