1 public class Square { 2 3 // Instance variable: 4 protected double width; 5 6 // Constructors: 7 public Square(double width) { 8 setWidth(width); 9 } 10 public Square() { } 11 12 // Encapsulate the instance variable: 13 public void setWidth(double width) { 14 this.width = width; 15 } 16 public double getWidth() { 17 return width; 18 } 19 20 // Instance methods: 21 public double perimeter() { 22 return 4*width; 23 } 24 public double area() { 25 return width*width; 26 } 27 28 }