overloadedconstructors.java
来自「java编程思想第四版习题答案」· Java 代码 · 共 33 行
JAVA
33 行
// initialization/OverloadedConstructors.java
// TIJ4 Chapter Initialization, Exercise 9, page 172
// Create a class with two (overloaded) constructors. Using 'this', call
// the second constructor from inside the first one.
class Doc {
Doc(int i) {
this("MD");
int yearsTraining = i;
System.out.println("New doc with " + i + " years of training");
}
Doc(String s) {
String degree = s;
System.out.println("New doc with " + s + " degree");
}
void intubate() {
System.out.println("prepare patient");
laryngoscopy();
}
void laryngoscopy() {
System.out.println("use laryngoscope");
}
}
public class OverloadedConstructors {
public static void main(String[] args) {
new Doc(8).intubate();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?