Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 472a99a

Browse files
committed
优化"能否在一个构造器中调用另一个构造器"
1 parent 73223a4 commit 472a99a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ stackoverflow-Java-top-qa
2929
* [Java 产生指定范围的随机数](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/generating-random-integers-in-a-range-with-Java.md)
3030
* [JavaBean 到底是什么](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/what-is-a-javabean-exactly.md)
3131
* [wait()和sleep()的区别](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/difference-between-wait-and-sleep.md)
32-
* [能否在一个构造器中调用另一个构造器](http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java)
32+
* [能否在一个构造器( `constructor` )中调用另一个构造器](http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java)
3333
> 编程技巧
3434
3535
* [去掉烦人的"!=null"(判空语句](https://github.com/giantray/stackoverflow-java-top-qa/blob/master/contents/avoiding-null-statements-in-java.md)

‎contents/How-do-i-call-one-constructor-from-another-in-java.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
##能否在一个构造器中调用另一个构造器
22

33
###问题
4-
能否在一个构造器中调用另一个构造器(在同一个类中,不是子类)?如果可以会怎样?
5-
那么调用另一个构造器的最好方法是什么(如果有几种方法可以选择的话)?
4+
能否在一个构造器中调用另一个构造器(在同一个类中,不是子类)?如果可以,怎么做?
5+
调用另一个构造器的最好方法是什么(如果有几种方法可以选择的话)?
66

77

88
###回答
9-
这样做是可以的。
9+
可以这样做:
1010
```java
1111
public class Foo
1212
{
@@ -23,7 +23,8 @@ public class Foo
2323
}
2424
}
2525
```
26-
如果你想链接到一个特定的父类构造器而不是本类的话,这里应该使用super,而不是this.
27-
请注意,你只能链接到一个构造器,并且调用语句必须是这个构造器的第一个语句。
26+
如果你想调用一个特定的父类构造器,而不是本类的构造器,应该使用super,而不是this.
27+
请注意,在构造器中,你只能调用一次其他的构造器。并且调用其他构造器的语句,必须是这个构造器的第一个语句。
28+
2829
stackoverflow原址:
2930
http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /