2013年9月10日星期二

I might ask a nested class inside the method in which a variable name to the external class assignments do

There is a nested class :
class out {
String name;
class in {
String type;
func (String type) {
this.type = type;
}
}
}
I might ask for name assignment func way inside you ?
------ Solution ------------------------ --------------------
class Out{
String name;

public void fun2(){
in i = new in();
i.fun();
System.out.println("out-->" + name);
}

class in{
//String name; //如果这里同名好像会把Out里面的覆盖
public void fun(){
//this.name = "in";
name = "out";
//System.out.println("in-->" + this.name);
}
}

public static void main(String[] args) {
Out o = new Out();
o.fun2();
}
}

possible
------ For reference only -------------------------------- -------
inner classes can
------ For reference only ------------------------ ---------------
Thank you very much , the answer very quickly .
------ For reference only -------------------------------------- -
I tried not, the result is null. Hope that helps.
------ For reference only -------------------------------------- -
can, in the in the inside can not have name, or the name can not be assigned inside out , only to get a null.

没有评论:

发表评论