Question

Design and Implement an Inheritance and Method overriding Model using following classes. Create a base class...

Design and Implement an Inheritance and Method overriding Model using following classes.

Create a base class named TwoDShapes. This class should have one field length and one method called Area.
Create a subclass named Square ,that extends TwoDShapes and calculates Area of the Square by overriding method called Area.
Use the key word this for using the length field from super class.
Create another sublclass Rectanagle extending TwoDShapes and calculate area by overriding Area method.
Create another subclass Circle extending TwoDshapes and calculate Area by overriding Area method.

Create a driver class that has a main method and create instances of Square ,Rectangle and Circle classes. Display the area of all on console using overridden area method.

coding language = java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

class TwoDShapes{

double length;

public void Area(){

System.out.println("From TwoDShapes class");

}

}

class Square extends TwoDShapes{

public void Area(){

System.out.println("Overridden area method from Square class");

}

}

class Rectangle extends TwoDShapes{

public void Area(){

System.out.println("Overridden area method from Rectangle class");

}

}


class Circle extends TwoDShapes{

public void Area(){

System.out.println("Overridden area method from Circle class");

}

}

public class TwoDShapesDriver{

public static void main(String[] args) {

TwoDShapes twoDShapes = new TwoDShapes();

Square square = new Square();

Rectangle rectangle = new Rectangle();

Circle circle = new Circle();

twoDShapes.Area();

square.Area();

rectangle.Area();

circle.Area();

}

}

Add a comment
Know the answer?
Add Answer to:
Design and Implement an Inheritance and Method overriding Model using following classes. Create a base class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT