Eighth java jobs

I, entitled

Second, the source code

Juxing.java

/ * 
Create a new package zz, seeking to create a rectangular package perimeter Juxing class
subclasses define another Zhengfang, inheritance Juxing parent class
creates a square area demand method, a method of rewriting request square perimeter
* /

ZZ Package;
class Juxing { public Double m; // Create member variables m, n-; public Double n-; public static Double zhouchang ( Double m, Double n-) { // create a perimeter constructor return ((n-m +) * 2 ); } } class Zhengfang the extends Juxing { public static Double Area ( Double m) { return (m*m); } public static double getzhouchang(double m, double n) { return (m *4); } }

Text1.java

/ * 
Create the same package main class Text1,
create a new object Zhengfang;
New Method for the area and perimeter requirements call Zhengfang
output
* /


Package ZZ; Import java.util.Scanner;
public class Text1 { public static void main (String [] args) { the System. OUT .println ( " enter a square side length: " ); Scanner Reader = new new Scanner (. the System in ); Zhengfang ZF = new new Zhengfang (); zf.m = reader.nextDouble (); . System OUT .println ( "Area of the square " + (* zf.m zf.m)); . The System OUT .println ( " square perimeter " + (* zf.m . 4 )); } }

 

Third, the operating results

 

Guess you like

Origin www.cnblogs.com/wanghainan/p/11577893.html