I, entitled
Write an application, and then create a rectangle class, a class with a long, wide two member variables and methods find the circumference.
Then create a rectangular square Subclass ----- classes, methods defined in the class seeking area, perimeter override method, in the main category, enter a side of the square, the square object is created
Square area and perimeter requirements.
Second, the source
(1) Rectangle class
Package ccut; / ** This is potentially a rectangular length and width, as well as methods seek rectangular perimeter * / public class the Rectangle { Double length; // length of the rectangle Double width; // rectangular wide // definition of peripheral method long Double getPer () { return 2 * (length + width); } }
(2) Square class
Package ccut; / ** This class defines the main method for finding the square area, perimeter rewriting process * / public class Square the extends the Rectangle { Double the getArea () { return length * length; } Double getPer () { return length * 4 ; } }
(3) Test Class
Package ccut; Import java.util.Scanner; public class the Test { / ** * such tests, a square perimeter and area * / public static void main (String [] args) { Scanner Reader = new new Scanner (the System.in) ; System.out.println ( "Please enter the side length of the square" ); // create objects square square sq = new new square (); sq.length = reader.nextDouble (); System.out.println ( "square area is: "+ sq.getArea ()); System.out.println ( " square perimeter "+sq.getPer()); } }
Third, the operating results map