mirror of
https://gitee.com/gaohongy/Java-Book.git
synced 2026-07-16 10:43:51 +00:00
修正类基础的部分
This commit is contained in:
+17
-1
@@ -180,9 +180,16 @@ public class Circle_Test {
|
||||
}
|
||||
```
|
||||
|
||||
> A class may be defined without constructors. In this case, a no-arg constructor with an empty body is implicitly defined in the class. This constructor, called a default constructor, is provided automatically only if no constructors are explicitly defined in the class.
|
||||
|
||||
如果你写了一个带参数的构造函数,建议写一个不带参数的构造函数,这样会省掉很多麻烦,后面会讲述。关于构造函数,会在后面的学习中详细讲述。
|
||||
|
||||
**注意,构造函数不能声明为私有的,不能声明为静态的,不能写返回参数!**
|
||||
**注意,构造函数一般不声明为私有,不能声明为静态的,不能写返回参数!**
|
||||
|
||||
其他的一些例子:
|
||||
|
||||
1. TestSimpleCircle
|
||||
2. TestTv
|
||||
|
||||
|
||||
|
||||
@@ -235,6 +242,11 @@ if (c1 == null) { // 可以判断一个引用变量是否没有被赋值
|
||||
}
|
||||
```
|
||||
|
||||
SDK中的一些类:
|
||||
|
||||
1. The Random Class
|
||||
2. The Point2D Class
|
||||
|
||||
|
||||
|
||||
## 4. 类的成员
|
||||
@@ -255,6 +267,8 @@ if (c1 == null) { // 可以判断一个引用变量是否没有被赋值
|
||||
|
||||
下面的例子中在`CircleWithStaticMembers`这个类中定义了一个静态变量`static int numberOfObjects = 0;`用来统计`CircleWithStaticMembers`这个类一共被创建出了几个对象。
|
||||
|
||||

|
||||
|
||||
```java
|
||||
class CircleWithStaticMembers {
|
||||
double radius;
|
||||
@@ -509,6 +523,8 @@ public class Test {
|
||||
|
||||
下面看看数组中的元素是引用类型的情况,借用上个例子的`CircleWithPrivateDataFields`类型。
|
||||
|
||||

|
||||
|
||||
```java
|
||||
public class TotalArea {
|
||||
/** Main method */
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
Reference in New Issue
Block a user