Question: 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
java code Create a class called 'Shape' that has two fields: 'name'

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!