输出结果:Person()
Teacher(String)
Teacher()
Faculty()
程序正陪先执行main方法,因为Faculty继承了Teacher类,兄此所以要执行Teacher的无参构造方法,但是Teacher类又继承了Person类,所以在执行Teacher的构造方法之前,要先执行Person的无参构造方法,打印Person(),接着执行Teacher的无参构造方法,里面调用了有参构造方法Teacher(String s),打印Teacher(String)和Teacher(),最后才是举尘蠢执行Faculty的无参构造方法打印Faculty()。希望能帮助到你!!!
package extend/**
* 圆类
* @author 枫雅
* 2019年3月21日
*/
public class Circle {
private double r
public final static double PI = 3.14
public Circle(double r) {
this.r = r
}
public double Circumference(double r) {
return 2*PI*r
}
public double Area(double r) {
return PI*r*r
}
} package extend
/**
* 圆柱类,继承自圆类
* @author 枫雅
* 2019年3月21日
*/
public class Cylinder extends Circle{
private double h
public Cylinder(double r, double h) {
super(r)
this.h = h
}
public double CeArea(double r, double h) {
return super.Circumference(r)*h
}
public double Volume(double r, double h) {
return super.Area(r)*h
}
} package extend
/**
* 圆锥类,继承自圆柱类
* @author 枫雅
* 2019年3月21日
*/
public class Cone extends Cylinder{
public Cone(double r, double h) {
super(r, h)
}
public double CeArea(double r, double h) {
return super.CeArea(r, h)/2
}
public double Volume(double r, double h) {
return super.Volume(r, h)/3
}
} package extend
/**
* 测试类
* @author 枫雅
* 2019年3月运升散21日
*/
public class Test {
public static void 旁氏main(String[] args) {
double r = 3
double h = 2
Circle circle = new Circle(r)
System.out.println("半径为:" + r + " 圆的周长为:" + circle.Circumference(r))
System.out.println("半径为:" + r + " 圆的面积为:" + circle.Area(r))
Cylinder cylinder = new Cylinder(3, 2)
System.out.println("底部半径为:"笑悄 + r + ",高为:" + h + " 圆柱的侧面积为:" + cylinder.CeArea(r, h))
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆柱的体积为:" + cylinder.Volume(r, h))
Cone cone = new Cone(3, 2)
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆锥的侧面积为:" + cone.CeArea(r, h))
System.out.println("底部半径为:" + r + ",高为:" + h + " 圆锥的体积为:" + cone.Volume(r, h))
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)