标签:generate main 抽象方法 ring sys cdc width tco shape
class Shape
1 package com.shape; 2 3 public abstract class Shape { 4 double area;// 5 double per;// 6 String color;// 7 public Shape() { 8 } 9 public Shape(String c){ 10 this.color=c; 11 } 12 abstract double getArea(); 13 abstract double getPer(); 14 abstract void showAll(); 15 public void getColor(String c){ 16 this.color=c; 17 18 } 19 20 }
class Rectangle
1 package com.shape; 2 3 public class Rectangle extends Shape{ 4 double Width;// 5 double height;// 6 7 @Override 8 double getArea() { 9 return super.area=Width*height; 10 } 11 12 @Override 13 double getPer() { 14 return super.per=Width*2+height*2; 15 } 16 17 @Override 18 void showAll() { 19 // TODO Auto-generated method stub 20 System.out.println("???ε???????"+getArea()+"????"+getPer()); 21 } 22 public Rectangle(){} 23 public Rectangle(double w,double h){ 24 this.Width=w; 25 this.height=h; 26 } 27 28 }
class Circle
1 package com.shape; 2 3 public class Circle extends Shape{ 4 double radius;//?? 5 6 @Override 7 double getArea() { 8 return super.area=radius*3.14*radius; 9 } 10 11 @Override 12 double getPer() { 13 return super.per=2*radius*3.14; 14 } 15 16 @Override 17 void showAll() { 18 // TODO Auto-generated method stub 19 System.out.println("??ε???????"+getArea()+"????"+getPer()); 20 } 21 public Circle(double r){ 22 this.radius=r; 23 } 24 public Circle(String c){ 25 this.color=c; 26 27 } 28 }
text
package com.shape; public class text { public static void main(String[] args) { Rectangle r=new Rectangle(3.0,4.0); r.showAll(); Circle c=new Circle(5.3); c.showAll(); } }
标签:generate main 抽象方法 ring sys cdc width tco shape
原文地址:http://www.cnblogs.com/lc-java/p/7392409.html