专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java相关

求高手!解决办法

发布时间:2010-06-05 14:18:44 文章来源:www.iduyao.cn 采编人员:星星草
求高手!!!!!!!!
public class Test {
static String a="string-a";
static String b;

String c= "string-c";
String d;

static{
printStatic("before static");
b="string -b";
printStatic ("after static");

}
public static void printStatic(String title){
System.out.println("********"+title+"*********");
System.out.println("a="+a);
System.out.println("b="+b);

}
public Test(){
print("before constructer");
d="string-d";
print("sfter constructer");

}
public void print(String title){
System.out.println("********"+title+"*********");
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
System.out.println("d="+d) ;
}
public static void main (String args[]){
new Test();


}

}





最后一句什么意思??????????


------解决方案--------------------
new Test();
就是调用构造函数嘛,只不过是个匿名对象而已,是为测试用的,对用只用一次。
和普通实例化一个对象一样。
Test test = new Test();
结果一样。
------解决方案--------------------
new Test()
调用Test类得构造方法,即调用
public Test(){
print("before constructer");
d="string-d";
print("sfter constructer");
}



------解决方案--------------------
创建匿名实例对象,就是不用名字引用,只使用一次可以这样创建
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: