day09-抽象类的练习
This commit is contained in:
@@ -9,6 +9,12 @@ public class Rectangle extends Shape{
|
||||
super(chang,kuan,0.0);
|
||||
}
|
||||
|
||||
public Rectangle(double bc){
|
||||
//通过父类的构造方法,将长宽存储起来
|
||||
// super(bc,bc,0.0);
|
||||
this(bc, bc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
//长*宽
|
||||
|
||||
11
day09/src/com/inmind/abstract07/test/Square.java
Normal file
11
day09/src/com/inmind/abstract07/test/Square.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.inmind.abstract07.test;
|
||||
|
||||
public class Square extends Rectangle{
|
||||
|
||||
//定义一个正方行,必须要知道边长,
|
||||
public Square(double bc){
|
||||
//调用父类构造时,只需要传递一个参数
|
||||
super(bc);
|
||||
}
|
||||
//直接继承父类的非私有的方法即可
|
||||
}
|
||||
@@ -34,5 +34,8 @@ public class Test08 {
|
||||
|
||||
//此时如何快速定义出一个正方行的类,还不用自己实现周长和面积的方法,但是能获取周长和面积!!!
|
||||
//提示:1.正方形是一个特殊的长方形 2.继承是可以多层继承的
|
||||
Square square = new Square(2);
|
||||
System.out.println(square.getArea());
|
||||
System.out.println(square.getZC());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user