Thread: super()

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13

    super()


    i know what
    super.someMethod();
    does, but how about:
    super();

    i've often seen it used within a contructor's body:
    Code:
    public SomeClass {
            protected member;
            
            public SomeClass() {
                      super();
            }
    }

    thanks in advance.


    =-=-=-=-=-=-=-=-=
    justin.dago
    =-=-=-=-=-=-=-=-=
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    30
    Rep Power
    57
    It calls the constructor for the superclass.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    that's what i suspected... thanks

    i've enjoyed your site for quite some time now.. thanks



    ______________________
    justin.dago
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    0
    Rep Power
    0
    Super() must only appear in the child class' matching constructor, and must be the first line.

    eg:
    ----------------------------------------------------------
    public class Parent {

    public Parent() {
    // A
    }

    public Parent(String str) {
    // B
    }

    }
    ----------------------------------------------------------
    public class Child extends Parent {

    public Child() {
    super(); // calls A
    // do more
    }

    public Child(String str) {
    super(); // calls B
    // do more
    }

    }
    ----------------------------------------------------------

IMN logo majestic logo threadwatch logo seochat tools logo