class Soap {
private String s;
Soap(){
System.out.println("Soap()");
s="Constructed"; }
public String toString() {
return s; }
}
class Bath {
private String
s1 ="happy",
s2 = "happy",
s3,s4;
private Soap castille;
private int i;
private float toy;
public Bath() {
System.out.println("Inside Bath()");
s3 = "Joy";
toy = 3.14f;
castille = new Soap(); }
{
i=47;
}
public String toString(){
if(s4==null)
s4 = "Joy";
return
"s1 = " + s1 +"\n"+
"s2 = " + s2 +"\n"+
"s3 = " + s3 +"\n"+
"s4 = " + s4 +"\n"+
"i = " + i +"\n"+
"toy = " + toy +"\n"+
"castille =" + castille;
} public static void main(String[] args) {
Bath b = new Bath();
System.out.println(b);
}
}

  输出

Inside Bath()
Soap()
s1 = happy
s2 = happy
s3 = Joy
s4 = Joy
i = 47
toy = 3.14
castille =Constructed

  来自thinking in java

最新文章

  1. Erlang垃圾回收机制的二三事
  2. iOS 钥匙串 指纹识别 get和Post请求的区别
  3. UnionPay,ChinaPay 最新 银联支付接口C#\Asp.net\MVC 版本
  4. 【循序渐进学Python】11.常用标准库
  5. Linux平台Makefile文件的编写基础入门(课堂作业)
  6. PHP中的文件下载
  7. python练习程序(c100经典例21)
  8. HIVE Transform using 用法
  9. 4k 对齐,你准备好了吗?
  10. DBCONN
  11. 基于OSGi的企业级快速开发平台(开源)
  12. 《Java并发编程实战》第十四章 构建自己定义的同步工具 读书笔记
  13. SQL__用命令删除定期的备份数据库文件
  14. PHP CodeBase: 生成N个不重复的随机数
  15. python基础整理----基本概念和知识
  16. sql server 高可用故障转移(2)
  17. newJob_newFell
  18. [luogu3455][POI2007]ZAP-Queries【莫比乌斯反演】
  19. 使用MyEclipse建立working set
  20. T550 HiDPI Ubuntu 16.04安装流水帐

热门文章

  1. Java – Try with Resources
  2. 使用IDEA编写JDBC
  3. STM32F103ZET6 PWM输出
  4. 非参数估计——核密度估计(Parzen窗)
  5. Cacti监控服务
  6. 怎么用scratch做大鱼吃小鱼
  7. 使用css动画实现领积分效果
  8. Python模块---制作属于自己的有声小说
  9. 关于wget下载jdk问题解决
  10. redis中的缓存-缓存雪崩和缓存穿透