forked from usf-cs272-fall2022/lectures
/
Square.java
62 lines (53 loc) · 1.13 KB
/
Square.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package edu.usfca.cs272;
/**
* Demonstrates several inheritance concepts, including basic inheritance,
* upcasting and downcasting, nested classes, and anonymous classes.
*
* @see ShapeDemo
* @see Shape
* @see Rectangle
* @see Square
*
* @author CS 272 Software Development (University of San Francisco)
* @version Fall 2022
*/
public class Square extends Rectangle {
/*
* What will be the shapeName in this case?
*/
/**
* Initializes a square with the specified width.
*
* @param width the width of the square
* @see Rectangle#Rectangle(double, double)
*/
public Square(double width) {
super(width, width);
debug("Square(double)");
}
/**
* Initializes a square with no width.
*
* @see #Square(double)
*/
public Square() {
this(0.0);
debug("Square()");
// What about calling super() instead?
}
/**
* Demonstrates the constructor chaining.
*
* @param args unused
*/
public static void main(String[] args) {
Shape.debug = true;
new Rectangle(1.0, 2.0);
System.out.println();
new Rectangle();
System.out.println();
new Square(3.0);
System.out.println();
new Square();
}
}