Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve it using JAVA Problem 2 [ 3 marks ] : Write an inheritance hierarchy for classes Point, Circle and Cylinder. Use point as the
Solve it using JAVA
Problem marks:
Write an inheritance hierarchy for classes Point, Circle and Cylinder. Use point as the
super class of the hierarchy. Specify the instance variables and methods for each class.
The private instance variables of Point should be coordinates of the point, provide
set and get methods to manipulate the private instance variables. Class Point should
contain a toString method which returns the formatted point coordinates ie
classes Circle and cylinder should inherit class point, class circle will contain radius of
the circle as instance variable it will inherit the instance variables, the constructor of
class Circle should call the base class constructor to initialize inherited instance
variables. Also, circle class will contain a method to calculate the area of the circle.
Moreover, class circle will provide an overridden version of method toString, there will
be a call of the superclasse's toString method to do a part of the work. Class cylinder
will do the same as described for the Circle class. In addition, it will have an instance
variable height. Moreover, class Cylinder must contain a method to calculate the volume
of the Cylinder object. Write a program that instantiates objects of your classes and
outputs the area of the circle and cylinder objects.
The following is a sample inputoutput
coordinate is
coordinate is
Radius is
The neu location and radius of circle areCenter ;
Radius
Area is
coordinate is
coordinate is
Radius is
Height is
The neu location, radius and height of cylinder are
Center
Radius ; Height
hadius ; Height
Jolune is
Press any key to continueSol
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