Define an class named Figure containing: Two instance variable named dim1, dim2 of type double. A full parameterized constructor which initiaizes the instance variables. A method named area which returns double and also prints a message as “Area for Figure is undefined”. Define another class named Rectangle which is extended from class Figure containing: A two parameter constructor which initializes all the instance variables of its super class (by calling its constructor). An overridden method named Area which returns the calculated area of the rectangle: (L*W). Define another class named Triangle which is extended from class Figure containing: A two parameter constructor which initializes all the instance variables of its super class (by calling its constructor). An overridden method named Area which returns the calculated area of the triangle: (L*W)/2. Define a third class named FindArea
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Define an class named Figure containing:
- Two instance variable named dim1, dim2 of type double.
- A full parameterized constructor which initiaizes the instance variables.
- A method named area which returns double and also prints a message as “Area for Figure is undefined”.
Define another class named Rectangle which is extended from class Figure containing:
- A two parameter constructor which initializes all the instance variables of its super class (by calling its constructor).
- An overridden method named Area which returns the calculated area of the rectangle: (L*W).
Define another class named Triangle which is extended from class Figure containing:
- A two parameter constructor which initializes all the instance variables of its super class (by calling its constructor).
- An overridden method named Area which returns the calculated area of the triangle: (L*W)/2.
Define a third class named FindArea contains a main method that test the functionality of the above classes by using super class reference..
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images