1. (TCO A) Consider the class Octagon given below: public class Octagon { privat
ID: 3541070 • Letter: 1
Question
1. (TCO A) Consider the class Octagon given below:
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 + ">" ;
}
}
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
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 + " " + oct2);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.