20194653- Object Oriented 1-- inheritance depth summary

topic:

A source code

1.rec。java

/ *** 
	 * @author X1393 
	 * Create class contains rec 
	 * l rectangular member variable length 
	 * width h is a member variable rectangular 
	 * member variable rectangular area area 
	 * seeking methods funC perimeter of a rectangle 
	 * / 
public class {REC 
		Double L; 
		Double H; 
		public Double FUNC () {// find the rectangular perimeter 
			
			return 2 + 2 * L * H; 
				} 
		
	}

 

2.squa。java

/ ** 
 * Create a rectangular square class category subclass rec squ class contains 
 methods square area demand * 
 * find the circumference rewriting rectangular perimeter squares method seeking 
 * / 
public class SQUA the extends rec { 
	public Double FunArea for (A Double ) { 
		return A * A; 
	} 
	public Double FUNC (Double A) {// find the circumference rectangular rewriting method 
		return. 4 * A; 
	} 

}

 

3.Tset。java

/ ** 
 * Create master class contains a main method 
 * squa define an object class rectangle whose T 
 * find the area and perimeter requirements call a method of obtaining a square perimeter and area 
 * / 
Import java.util.Scanner; 
public class Tset is { 

	/ ** 
	 * @param args 
	 * / 
	public static void main (String [] args) { 
		// the TODO Auto-Generated Stub Method 
		System.out.println ( "square side length"); 
		Scanner Scanner Reader new new = (the System.in) ; 
		Double reader.nextDouble X = (); 
		SQUA SQUA new new = T (); // definition of the object class square T 
		System.out.println ( "area of" + T.funarea (X)); 
		System.out.println ( "circumference" + T.funC (X)); 
	} 

}

Second, the operating results

 

Guess you like

Origin www.cnblogs.com/Xwwg/p/11579587.html