Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that there are two ways of reusing existing classes: composition and inheritance. We have seen that a MyLine class can be implemented using composition

image text in transcribed

Recall that there are two ways of reusing existing classes: composition and inheritance. We have seen that a MyLine class can be implemented using 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 Point class "A line is a point extended by another point". Let's call this subclass MySubLine (to differentiate from the MyLine class using composition) The MySubLine class is designed as shown in the class diagram. It contains: . Two MyPoint objects; but you only need to declare one instance variable inside the class (ie. end) . A constructor that constructs a line from four integer values. An overloaded constructor that constructs a MySubline object with two MyPoint objects. . A tostring() method that returns a string description of the line in this format: (x1, y1) to (x2, y2) . A method 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

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

More Books

Students also viewed these Databases questions

Question

5 . What are the two building blocks of all classical ciphers?

Answered: 1 week ago