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
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
Get step-by-step solutions from verified subject matter experts
