Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

java code Create a class called 'Shape' that has two fields: 'name' and 'sides'. The 'Shape' class should have a constructor that takes in the

java code
image text in transcribed
Create a class called 'Shape' that has two fields: 'name' and 'sides'. The 'Shape' class should have a constructor that takes in the 'name' and 'sides' as arguments and sets their values. The 'Shape' class should also have a method called 'getInfo' that prints the name and number of sides of the shape to the console. Create a subclass of 'Shape' called 'Triangle' that overrides the 'getinfo' method to print the name and number of sides of the triangle to the console. The 'Triangle' class should also have a method called 'getArea' that calculates nnd returns the area of the triangle using the formula ' 0.5 * base * height', where 'base' and 'height' are parameters of the 'getArea' method. Create a main method that creates an instance of the 'Triangle' class and calls its 'getinfo' and 'getArea' methods using polymorphism

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students explore these related Databases questions