Question
Part 2: Interfaces As covered in lectures, an interface is a set of methods. When a class implements an interface, the methods in the interface
Part 2: Interfaces
As covered in lectures, an interface is a set of methods. When a class implements an interface, the methods in the interface must be implemented in the class. The methods are not implemented in the interface, just listed.
1. Set up an interface called ThreeDShape that represents a 3D shape. Include an abstract method that allows the calculation of the volume of the 3D shape.
2. Amend the class hierarchy for shape to include two new subclasses representing the 3d shapes, cube and sphere. Get these classes to implement your new interface ThreeDShape. Hint 1: When a class implements an interface, it has to implement all methods in the interface. Hint 2: Implements keyword
3. Implement the area() method for the two new classes (cube and sphere) to return the surface area of the shape.
4. Modify the test class to test the new classes and methods you have added by including the new shapes (cube and sphere)in the array you have setup
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