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.
Code:
/ ** JvXing class (class rectangle): member defines three variables, length a, width B, C circumference, a public authority getzhouchang find the circumference type method.
Zheng class (class square): JvXing is a subclass of class defines two member variables edge length d, Area area, a square area demand method, a method of rewriting request perimeter.
Test the main class: create a square object, call seeking square area and perimeter and output. * /
package cn.edu.ccut.po; import java.util.*; class JvXing{ double a; double b; double c; public double getzhouchang(double a,double b){ c=(a+b)*2; return c; } } class Zheng extends JvXing{ double d; double area; double getarea(double d){ area= d*d; return Area; } public Double getzhouchang ( Double C, Double D) { return . 4 * D; } } public class the Test { public static void main (String [] args) { Scanner R & lt = new new Scanner (the System.in); the System. Out.println ( "enter a square side length:" ); Double D = r.nextDouble (); Zheng Z = new new Zheng (); System.out.println ( "area of the square:" + z.getarea (D)) ; System.out.println ( "square perimeter:" + z.getzhouchang (D, D)); } }
Run shot