Java
In the following Point class
create the toString() method (as you know the toString()method is used in the System.out.println() calls when you areprinting an object not necessarily a String)
in main() method
-- using the constructor create a new point p=(2,3) -- create a copy of p using p.getLocation() -- two other tasks are described with comments within thecode below
The incomplete main() for the Point classand the corresponding output is included below
Output:
2. Consider the subclass ColoredPoint (below) whichextends Point.
--Complete the toString() method which returns a Stringproviding info about your object (to be used in yourSystem.out.println() method) --Complete the new methods such as setColor() and getColor()(as indicated with "code here").--Complete the two constructors , noteyou will need the keyword super which refers to thesuperclass constructor
The complete main() and the corresponding output is shownbelow
Output:
Java In the following Point class create the toString() method (as you know the toString() method is used in the System
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am