public ByteValue(){
   super();//这个super是什么意思?
   system.out.println(.....);
}
这句话的作用是什么 ?

解决方案 »

  1.   


    楼主回去找本java基础书,仔细看看。
      

  2.   

    super();//这个super是什么意思? 
    这句话只能用在子类构造函数的第一句
      

  3.   

    super 与 this 是两个对应的指针,this是指向当前类的对象的,而super是指向父类的,这里用来初始化父类
      

  4.   

    调用父类的构造函数,与this对应
      

  5.   

    搂主应该巩固一下java的基础了。
      

  6.   

    很基础的Java基础知识 如果这都不知道说明你可能这几天才开始接触Java
      

  7.   

    java类初始化的时候先要调用父类的构造方法,然后是子类的构造方法。在子类构造方法的第一行,显式或者隐式调用了父类的构造方法。如果是隐式调用(不写super()方法),系统会默认执行默认的父类构造方法super(),当然可以显式调用,比如super("nihao")这样。
    今天加班,等着发版本,好无聊
      

  8.   

    拜托!发贴时请注意你是否已经将最基础的东西学好~~!然后建议看《Thinking in Java》已经是第四版了吧~!你会发现原来是这样~!雾水不自而解....
      

  9.   

    QQ137890732:   和楼上的很多兄弟说的一样,就是调用父类的构造方法,先要构造出父类,才有完整的自己。因为自己包含了父类,就象C++是C的超集合一样,如果世界上没有C这样的语言,就不会有C++一样,不知道这样解释,比较实在不。
      

  10.   

    qq 345659710刚学JAVA 来差不多的一起探讨
      

  11.   


    貌似要了解这个问题还轮不到需要看《Thinking in Java》吧
      

  12.   


    java 构造函数调用顺序 
    当一个复杂的对象被构造时,它的构造函数按下面的顺序被调用(that the order of constructor calls for a complex object is as follows) 
        1.其基类(base-class)的构造函数被调用,这个步骤以递归的方式重复,所以最底层(the root of hierarchy)的构造函数首先被执行,然后是它上一层派生类(the next-derived class)...直到最顶层的派生类(the most-derived class).The base-class constructor is called. This step is repeated recursively such that the root of the hierarchy is constructed first, followed by the next-derived class, etc., until the most-derived class is reached.)    2.如果有包含关系(composition),那么它的成员对象按照声明的顺序被构造.Member initializers are called in the order of declaration.    3.派生类构造函数的内容(body)被执行.The body of the derived-class constructor is called.    一个实例:
    class Cake{
       Cake(){System.out.println("Cake()");}
    }class Meal {
      Meal() { System.out.println("Meal()"); }
    }class Bread {
      Bread() { System.out.println("Bread()"); }
    }class Cheese {
      Cheese() { System.out.println("Cheese()"); }
    }class Lettuce {
      Lettuce() { System.out.println("Lettuce()"); }
    }class Lunch extends Meal {
      Lunch() { System.out.println("Lunch()"); }
    }class PortableLunch extends Lunch {
       //if make derived-class object as the menber of the base-class will lead a infinite
       //loop and program will stop because of the memory consumed
       
       //private Sandwich s=new Sandwich(); 
      private Cake a=new Cake();
      PortableLunch() { System.out.println("PortableLunch()");}
    }public class Sandwich extends PortableLunch
    {
      private Bread b = new Bread();
      private Cheese c = new Cheese();
      private Lettuce l = new Lettuce();
      
      public Sandwich() {
        System.out.println("Sandwich()");
      }
      
      public static void main(String[] args)  {
        new Sandwich();
      }
    }
    输出:Meal()
    Lunch()
    Cake()
    PortableLunch()
    Bread()
    Cheese()
    Lettuce()
    Sandwich()   main()函数中要构造一个Sandwich的对象,调用(并不是执行)它基类PortableLunch的构造函数,PortableLunch又递归的调用,然后是Meal,Meal是继承的最底层的基类(不算Object)所以它的构造函数首先被执行,然后按次序返回到Lunch, PortableLunch,但在PortableLunch的构造函数被执行之前,它的成员对象Cake a先按照声明的顺序被构造.然后执行PortableLunch(),接着是Sandwich的成员对象,最后是Sandwich().注:被注释掉的代码,将base-class的对象作为derive-class的成员对象,这样会递归无法结束,最后程序因堆栈耗尽而结束(Exception in  thread main java.lang.StackOverflowError).
      

  13.   

    这里的super是调用父类的无参构造方法