java类中的私有非静态成员能直接在类中初始化?
public class InnerClasses
{
private static String staticAttribute = "Outter class ' static attribute ";
private String instantiateAttribute = "Outter class ' instantiate attribute ";
public void instantiateMethod()
{
System.out.println( "Outter class ' intantiate method ");
}
public static void staticMethod()
{
System.out.println( "Outter class ' static method ");
}
public static class StaticInnerClass
{
public StaticInnerClass()
{
System.out.println( "static Inner class ");
}
public void access()
{
System.out.println(staticAttribute);
staticMethod();
}
}
public class InstantiateInnerClass
{
public InstantiateInnerClass()
{
System.out.println( "Instantiate Inner class ");
}
public void access()
{
System.out.println(instantiateAttribute);
instantiateMethod();
}
}
}
------解决方案--------------------那这样的话 每个对象的 这个 成员 初始值 都是一样的
如果在构造函数里再赋值
就可以得到不同初始值的对象