static String s = new String("null"); 你定义的是static,只能被初始化一次。 你可以看看关于static的资料
晕,那s个参数亚。你并没有执行this.s = s 什么的操作阿。
在Method(String s, int i)方法中,传过来的参数没有用到,而在void print()方法里是没有参数的,所以打印出来的只是上面的变量。
public class Method { int i = 0; static String s = new String("null"); Method() { this.s="adfafaf"; this.i=100; } Method(String s, int i) { System.out.println("this sucess"); } void print() { System.out.println("s = " + s + " i = " + i); } public static void main(String[] args) { Method t = new Method(); t.print(); } } 这样就能得到你想要的结果了。
public class Method { int i = 0; static String s = new String("null"); Method() { this("adfafaf",100); } Method(String s, int i) { this.s=s this.i=i } void print() { System.out.println("s = " + s + " i = " + i ); } public static void main(String[] args) { Method t = new Method(); t.print(); } } 就可以了.
你定义的是static,只能被初始化一次。
你可以看看关于static的资料
int i = 0; static String s = new String("null"); Method()
{
this.s="adfafaf";
this.i=100;
} Method(String s, int i)
{
System.out.println("this sucess");
} void print()
{
System.out.println("s = " + s + " i = " + i);
} public static void main(String[] args) {
Method t = new Method();
t.print();
}
}
这样就能得到你想要的结果了。
{
int i = 0;
static String s = new String("null");
Method()
{
this("adfafaf",100);
}
Method(String s, int i)
{
this.s=s
this.i=i }
void print()
{
System.out.println("s = " + s + " i = " + i );
}
public static void main(String[] args)
{
Method t = new Method();
t.print();
}
}
就可以了.