Question: Given the Class defined below, what is the output (please specify the output in the correct order)when the class is run using java Square ?


Given the Class defined below, what is the output (please specify the output in the correct order)when the class is run using java Square ? Explain why each output occurs. * An Object Implementation which Represents a 2-D Square public class Square extends Object implements Comparable Square private int Side = 0; private int myArea - @; private int myPerimeter 0; 70 Create a Square Object with a side value of zero. */ public Square() { this(); } 7 Creates a Square Object with a side value of Initialside @param Initialside Initial Side Value of Square Object M/ public Square (int Initialside ) { this.Setside( InitialSide ); /** Returns the side value for this Square = @return Integer Representing the side value for This Square Object */ public int GetSide() { return this. Side; public void Setside( int NewSideValue) { this.Side . NewsideValue; UpdateAreAndPerimeter(); } public int GetArea() { return this. myArea; public int GetPerimeter() { return this.myPerimeters) private void UpdateAreaAndPerimeter() this.myArea = this.Side . this.Side; this.myPerimeter = this.Side . 4; public String toString() { String temp; temp = new String(); temp = "I am a square with side " + this.Side", area of " + this.GetArea()+", r of this.GetPerimeter(); return temp; } and perimete Provides Natural Order Comparison for Square @return Integer Representing the Comprison based on Square Side Value public int compare To Square Test) ( 7/return this.Side - Test.Side; return Test.Side - this.Side; public static void main(String[] args) { Square A = new Square(5); Square B = new Square(5); if (A - B) { System.out.println("Square A and B are equal"); } else { System.out.println("Square A and B are NOT equal"); } if (A.compareTo(B) ==0) { System.out.println("COMPARABLE: Square A and B are equal in natural order (both have same s ide value"); ) A.Setside(); if (A.compareTo(B)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
