码迷,mamicode.com
首页 > 编程语言 > 详细

Java:thinging in java p158 exercise 1

时间:2015-04-19 11:34:00      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

Create a class with a String field that is initialized at the point of definition, and another one that is initialized by the constructor. What is the difference between the two approaches.

 1 class Test{
 2     String s1;
 3     String s2="hello world";
 4     String s3;
 5     Test(){
 6         s3="hello java";
 7     }
 8 }
 9 public class ConstructorTest {
10 
11     public static void main(String[]args){
12         
13         Test t=new Test();
14         System.out.println(t.s1);
15         System.out.println(t.s2);
16         System.out.println(t.s3);
17         
18     }
19 }

输出

null
hello world
hello java

 

Java:thinging in java p158 exercise 1

标签:

原文地址:http://www.cnblogs.com/taoxiuxia/p/4438783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!