当前位置: 代码迷 >> J2SE >> 关于对域的调用.解决方案
  详细解决方案

关于对域的调用.解决方案

热度:12   发布时间:2016-04-23 19:55:21.0
关于对域的调用.
public class aExtends {
private double salary = 5000; 
    
public static void main(String[] args) {


aExtends b = new aExtends();
System.out.println(b.salary);



}
 这个是正确的,是我最早接触的。


public class aExtends {

public static void main(String[] args) {

System.out.println(b.salary);

}

class employee{
 double salary = 5000; 
employee b = new employee();
}

这个是错误的,我还是不懂他的执行循序,错在哪里?


------解决思路----------------------
两个类的调用关系就好比两个人聊qq,需要一个平台,当我调用别人的类的时候需要别人的对象,但这个对象必须在自己一方实例化。
------解决思路----------------------

public class aExtends { 
    public static void main(String[] args) {
        employee b = new employee();   
        System.out.println(b.salary);
    } 
}
 
class employee{
     double salary = 5000;     
}

  相关解决方案