📄 ex15(1).java
字号:
// innerclasses/Ex15.java
// TIJ4 Chapter Innerclasses, Exercise 15, page361
/* Create a class with a non-default constructor and no default constructor.
* Create a second class that has a method that returns a reference to an
* object of the first class. Create the object that you return by making an
* anonymous inner class that inherits from the first class.
*/
class One {
private String s;
One(String s) { this.s = s; }
public String showS() { return s; }
}
public class Ex15 {
public One makeOne(String s) {
return new One(s) { };
}
public static void main(String[] args) {
Ex15 x = new Ex15();
System.out.println(x.makeOne("hi").showS());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -