public class Square extends Shape {
public Square(double length, double width) {
super(length, width);
}
public void getArea() {
System.out.println("矩形的面积是:" + length*width);
}
public void getPerimeter() {
System.out.println("矩形的边长是:" + (length+width)*2);
}
}
public Square(double length, double width) {
super(length, width);
}
public void getArea() {
System.out.println("矩形的面积是:" + length*width);
}
public void getPerimeter() {
System.out.println("矩形的边长是:" + (length+width)*2);
}
}
2017-07-14
public class Circle extends Shape {
public Circle(double length) {
super(length);
}
double π = 3.14;
public void getArea() {
System.out.println("圆形的面积是" + π*length*length);
}
public void getPerimeter() {
System.out.println("圆形的边长是:" + 2*π*length);
}
}
public Circle(double length) {
super(length);
}
double π = 3.14;
public void getArea() {
System.out.println("圆形的面积是" + π*length*length);
}
public void getPerimeter() {
System.out.println("圆形的边长是:" + 2*π*length);
}
}
2017-07-14
public abstract class Shape {
double length,width;
public Shape(double length,double width) {
this.length = length;
this.width = width;
}
public Shape(double length) {
this.length = length;
}
public abstract void getArea();
public abstract void getPerimeter();
}
double length,width;
public Shape(double length,double width) {
this.length = length;
this.width = width;
}
public Shape(double length) {
this.length = length;
}
public abstract void getArea();
public abstract void getPerimeter();
}
2017-07-14
package ggjt;
public class Test {
public static void main(String[] args) {
Jjtgj myJjtgj = new Jjtgj();
Jjtgj bus = new Bus();// 多态的构造方法的重写,不影响类的,但是子类独立的方法父类不能引用
Jjtgj lc = new Lc();
Jjtgj fj = new Fj();
myJjtgj.yxfs();
bus.yxfs();
lc.yxfs();
fj.yxfs();
}
}
public class Test {
public static void main(String[] args) {
Jjtgj myJjtgj = new Jjtgj();
Jjtgj bus = new Bus();// 多态的构造方法的重写,不影响类的,但是子类独立的方法父类不能引用
Jjtgj lc = new Lc();
Jjtgj fj = new Fj();
myJjtgj.yxfs();
bus.yxfs();
lc.yxfs();
fj.yxfs();
}
}
2017-07-13