Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There are two ways of reusing existing classes: composition and inheritance. We have seen that a MyLine class can be implemented using a composition of
There are two ways of reusing existing classes: composition and inheritance. We have seen that a MyLine class can be implemented using a composition of MyPoint class - "a line is composed of two points", in the previous section. A Line can also be implemented using inheritance from the MyPoint class - "A line is a point extended by another point". Let's call this subclass MySubLine (to differentiate from the My Line class using composition). The MySubLine class contains the following . one instance variable inside the class (i.e. endPt) A default (or "no-argument" or "no-arg") constructor that constructs a line default values .A constructor that constructs a line from four integer values .An overloaded constructor that constructs a MySubLine object with two MyPoint objects .An overridden tostring) method that returns a string description of the line in this format: (x1, y1) to (x2, y2) Getter and setter for the instance variables startPt and endpt A method named getlength that returns the length of this line Write the MySubLine class in the answer box below assuming that the MyPoint class has been done for you in the system. For example Test Result MySubline line new MySubLine(1, 2, 3, 4);(1, 2) to (3,4) System.out.println(line)
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