topic
JuXing.java (rectangle class)
/ * Rectangle class defines three member variables length, width, zc, representing the length and width and girth, there is another method of seeking to hold the perimeter. * / Package COM; public class Juxing { public int length; public int width; public int ZC; int getZc () { ZC = (length + width) * 2 ; return ZC;} }
Zfx.java (square type)
/ * Subclasses inherit parent square rectangle class, two methods (perimeter squares method is a method wherein the rewritable) area and perimeter of the square find * / Package COM; public class ZFX the extends Juxing { int Area; int the getArea () { return Area * length = length; } int getZc () { ZC = (length) *. 4 ; return ZC;} }
App.java (test class)
/ * Create a square object, call seeking area perimeter method, the output return value. * / Package COM; Import java.util.Scanner; public class the App { public static void main (String [] args) {
System.out.println ( "Please enter the side length"); Scanner Reader = new new Scanner (the System.in ); ZFX ZFX = new new ZFX (); zfx.length = reader.nextInt (); System.out.println ( "area" + zfx.getArea ()); System.out.println ( "circumference" + ZFX .getZc ()); } }
Test run results