Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Figure Q3 shows the implementation of interface (Shape) marked by an arrow leading from the subclasses (Rectangle and Triangle) to the interface. Shape (Interface)

 

Figure Q3 shows the implementation of interface (Shape) marked by an arrow leading from the subclasses (Rectangle and Triangle) to the interface. Shape (Interface) +getArea(): double Rectangle Triangle -length double -width: double +getArea(): double -base double -height: double +getArea(): double Figure Q3: Shape interface implementation (a) Show the Shape interface in Java. (2 marks) (b) Show the Rectangle class definition with getArea method. (2.5 marks) (c) Show the Triangle class definition with getArea method. (2.5 marks) (d) Show how polymorphism works by using TestShape as a driver class to create new object and invoking both getArea methods according to following expected output. Rectangle [length-1, width=2] Area is 2 Triangle [base 3, height=4] Area is 6 (3 marks)

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

Step: 3

blur-text-image

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

Introduction To Programming In Java An Interdisciplinary Approach

Authors: Robert Sedgewick, Kevin Wayne

2nd Edition

0672337843, 9780672337840

More Books

Students also viewed these Programming questions

Question

What happens if I write code after a return statement?

Answered: 1 week ago