0

Actually i was going through some android source code and found these

public static class ToggleService extends IntentService {
super(ToggleService.class.getname());

I am not able to understand the use of super and also its parameters.

  • 1
    Possible duplicate of [super() in Java](https://stackoverflow.com/questions/3767365/super-in-java) – DarkCygnus Jun 26 '17 at 18:19
  • i know the use of super. –  Jun 27 '17 at 07:19
  • Then you should know what it does: `super` calls the constructor of its parent class (that is `IntentService`) with the name of this class (`ToggleService`) as parameter – DarkCygnus Jun 27 '17 at 13:21

3 Answers3

1

If you have at look at the documentation

https://developer.android.com/reference/android/app/IntentService.html#IntentService(java.lang.String)

you will find that IntentService (base class of ToggleService) has a constructor which takes a string for debugging purposes. Super calls the constructor of the base class. So ToggleService just supplies its own name for debug logs to be prefixed with it.

ElDuderino
  • 3,253
  • 2
  • 21
  • 38
1

Because ToggleService extends IntentService, by calling super from ToggleService, it is effectively calling IntentService's constructor, which is

     /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public IntentService(String name) {
        super();
        mName = name;
    }

ToggleService.class.getname() will return the name of the ToggleService class, which in this case is a concatenated string constructing the package name of ToggleService and "ToggleService".

For more info: https://docs.oracle.com/javase/tutorial/java/IandI/super.html

Simon
  • 202
  • 2
  • 5
0

super is a keyword in Java. It refers to the immediate parents property.

super()            //refers parent's constructor
super.getMusic();  //refers to the parent's method

Read More on super

SAYE
  • 1,247
  • 2
  • 20
  • 47