Title: writing an application, create a rectangle class, a class with a long, wide two member variables and methods find the circumference. Then create a subclass of the class of rectangular - square classes, methods defined in the class seeking area, find the circumference rewriting method. In the main class, the input side length of a square, a square object is created, the square area and perimeter requirements. (Note: all classes are in a package)
First, the source
/ ** find the area and perimeter of the square * two classes four methods * / Package W24; Import java.util.Scanner; class Rectangle { // a rectangular type int length, Wide; // having a length and width two member variable int girth () { // method find the circumference of the return (length + Wide) * 2 ; } } class square the extends rectangle { // subclass of a class of rectangular - square type int Area () { // find the method area return length * length; } int girth () { // method to find the circumference rewritable return length *. 4 ; } public static void main (String [] args) { Scanner Reader = new new Scanner (the System.in); // input length and width System.out.println ( "Please enter the side of the square" ); Z square = new new square (); // Create square objects z.length = reader.nextInt (); System.out.println ( "square area" + z.area () + "square perimeter" + Z. girth ()); } }
Second, the success Screenshots