Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started