Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the class Octagon given below: public class Octagon { private double si

ID: 3534238 • Letter: C

Question

Consider the class Octagon given below:

public class Octagon
{
private doubleside;

public Octagon()
{
side = 1;
}

public Octagon(double s)
{
side = s;
}

public double getSide()
{
returnside;
}

public void setSide(double d)
{
side = d;
}

public String toString()
{
return"<" + side + ">" ;
}
}


Write Java code that makes a shallow copy of octagon oct1 in the place indicated in the class Main given below.

import java.util.*;

public class Main
{
public static void main(String[] args)
{
Octagon oct1 =
new Octagon(2.5);

Octagon oct2 = /* write here Java code that produces a shallow copy */
System.out.println(oct1 + " " + oct2);
}
}


Explanation / Answer

public class Octagon
{
private double side;

public Octagon()
{
side = 1;
}

public Octagon(double s)
{
side = s;
}

public double getSide()
{
return side;
}

public void setSide(double d)
{
side = d;
}

public String toString()
{
return"<" + side + ">" ;
}
}

import java.util.*;


public class Main

{

public static void main(String[] args)

{

Octagon oct1 = new Octagon(2.5);


Octagon oct2 = oct1;

System.out.println(oct1.getSide() + " " + oct2.getSide());

}

}