0
3.3kviews
Create Rectangle and Cube class that encapsulates the properties of a rectangle and cube i.e. Rectangle has default and parameterized constructor and area() method.

Cube has default and parameterized constructor and volume method(). They share no ancestor other than Object. - Implement a class Size with size() method. This method accepts a single reference argument z. If z reference to a Cube, then size(z) return its volume. If z refers to an object of any other class, then size(z)- returns – 1. Use main() method in Size class to call size(..) method. -

Marks: 15 M

Year: Dec 2014

1 Answer
1
175views
class Rectangle {
    int length;
    int breadth;
    //Default constructor
    Rectangle() {
        length = 2;
        breadth = 2;
    }
    //Parameterized constructor
    Rectangle(int length, int breadth) {
        this.length = length;
        this.breadth = breadth;
    }
    //area method
    int area() {
        return length * breadth;
    }
}

class Cube {
    int side;
    //Default constructor …

Create a free account to keep reading this post.

and 5 others joined a min ago.

Please log in to add an answer.