java 8th inherited the job

I, entitled: width perimeter two member variables and methods seeking to write an application to create a rectangular type, a long class. 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)

Second, the source code:

1.Juxing.java

/ * Define the variable length of the rectangle is c, a width of a rectangular variable k, find a way to define a rectangular perimeter zhouchang. * / 
Package SZY; 

class Juxing {
     public  static  int C;
     public  int K;
     public  static  int zhouchang ( int C, int K) {
         return ((C + K) * 2 ); 
    } 

} 


/ * define a subclass zhengfangxing inherit Juxing parent class, method defines a square area demand, a method of rewriting request perimeter. * / 
Class zhengfangxing the extends Juxing {
     public  static  int getmianji () {
         return (C * C); 
    }
    public static int getzhouchang(){
        return(c*4);
    }
    
}

2.Text.java

/ * Create a class called Text class, a main method, the input side length of the square area and perimeter requirements, output. * / 
Package SZY; 
Import java.util.Scanner; 
public  class the Text {
     public  static  void main (String the Args []) { 
        the System. OUT .println ( " input side length: " ); 
        Scanner Reader = new new Scanner (the System. In ); 
        zhengfangxing ZFX = new new zhengfangxing (); 
        zfx.c = reader.nextInt (); 
        the System. OUT .println ( " square type area: " +zfx.getmianji ()); 
        . the System OUT .println ( " square perimeter: " + zfx.getzhouchang ()); 
        
        
        
        
    } 

}

Third, the result of the operation

 

Guess you like

Origin www.cnblogs.com/szy799/p/11580615.html