Results 1 to 3 of 3
  1. #1
    Octonami is offline Member
    Join Date
    May 2013
    Rep Power

    Default other uses for "super"?

    I am pretty to Java and am reading through a lot of examples and other people's classes I came across a use of super(); that threw me off:
    Java Code:
    public class Example
    	private static final Example[] lib = new Example[68];
    	public Example(){
    		final char c=Thread.currentThread().getThreadGroup().getName().charAt(0);
    		if(lib[c]==null) lib[c]=this;
    This class is not a subclass of anything, so I was a little confused by it showing up here and all google results point to super being for use in subclasses only. So i guess my question is: Are there other ways of using super?


  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: other uses for "super"?

    If a class doesn't explicitly extend another class, it implicitly extends from the Object class, the mother of all classes. It is kind of futile to call the no-args super class constructor with super() because if you leave it out, the compiler will do it for you.

    kind regards,

    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Rep Power

    Default Re: other uses for "super"?

    When you define a class

    Java Code:
    public class Example
    is the same as this:

    Java Code:
    public class example extends Object
    So in a way, when the Example class you build inherits Object and another class extends Example, it is basically multiple inheritance, but it is common to all classes.
    And since a few methods are inherited from Object you can call them with super. --- super.toString() for instance.

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 09:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 04:06 PM
  3. Syntax error on token "}", super expected
    By amentjacob1 in forum New To Java
    Replies: 9
    Last Post: 07-06-2012, 04:15 AM
  4. Reflection Invoking method of "super" class
    By Shellback3 in forum Advanced Java
    Replies: 2
    Last Post: 01-31-2011, 05:50 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts