/**4-3
* Derive a subclass for the rectangle class defined in Experiment 3: a square class. If the square operation is also to find the circumference and area
* What methods does this subclass need to define in addition to the methods inherited from the parent class?
* Lists all fields and methods of the square class.
* Programming to check, run the written square class
**/
public class firstprogram{public static void main (String[] args) {Square square1 = new square (8); Square square2 = new square (25); System.out.println ("the perimeter of square1 is: " + square1.perimeter ()); System.out.println ("the area of square1 is: " + square1.area ()); System.out.println ("the perimeter of square2 is: " + square2.perimeter ()); System.out.println ("the area of square2 is: " + square2.area ());}} class rectangle{protected int length;protected int width; rectangle () {}rectangle (int l, int w) {this.length = l;this.width = w;} int perimeter () {return (Length + width) * 2;} int area () {return length * width;}} class square extends&nBsp rectangle{protected int side; square (int side) {super (); this.side = side;} int perimeter () {return 4 * side;} int area () {return side * side;}}
Those years, learn together Java 4-3