Compare commits

..

2 Commits

Author SHA1 Message Date
高宏宇 8451eecc09 修改错别字 5 months ago
高宏宇 5f25030f7d 修改错别字 5 months ago

@ -23,7 +23,7 @@
例如要在平面上描述两个类圆和矩形那么这两个类好像有一些基本的特性是一致的。例如填充颜色color是否填充 filled对象创建时间 dateCreated等。另外需要对上述属性设置或者读取的方法getColor()setColor()isFilled()setFilled()等。
如果每个类都需要描述所有的这些特性好像有点浪费如何做到降低代码冗余我们使用到继承如下图表述GeometrocObject是父类保护所有子类共有的特性数据和方法Circle和Rectangle继承于GeometrocObject。这样在编写Circle和Rectangle的时候就只需要对其特性进行描述就可以了这两个类的共性在其父类中以及体现出来了子类完全继承父类的所有特性数据和方法
如果每个类都需要描述所有的这些特性好像有点浪费如何做到降低代码冗余我们使用到继承如下图表述GeometrocObject是父类包括所有子类共有的特性数据和方法Circle和Rectangle继承于GeometrocObject。这样在编写Circle和Rectangle的时候就只需要对其特性进行描述就可以了这两个类的共性在其父类中以及体现出来了子类完全继承父类的所有特性数据和方法
![image-20230311122706219](img/image-20230311122706219.png)
@ -90,7 +90,7 @@ public class SimpleGeometricObject {
可以看到父类对共有的变量和方法进行了定义,虽然父类可以实例化,但是好像实例化父类并没有什么实际的意义。
**注意:这个类最好不能被实例化,因为没有意义。下一章将借用这个离职,并使其不能被实例化。**
**注意:这个类最好不能被实例化,因为没有意义。下一章将借用这个例子,并使其不能被实例化。**
#### 1.2.2. 子类Circle
@ -244,7 +244,7 @@ public class TestCircleRectangle {
### 2.1. 构造函数也被继承了吗?
> No. They are not inherited.They are invoked explicitly or implicitly. Explicitly using the super keyword.
> No. They are not inherited. They are invoked explicitly or implicitly. Explicitly using the super keyword.
>
> A constructor is used to construct an instance of a class. Unlike properties and methods, a superclass's constructors are not inherited in the subclass. They can only be invoked from the subclasses' constructors, using the keyword super. If the keyword super is not explicitly used, the superclass's no-arg constructor is automatically invoked.

Loading…
Cancel
Save