user8086643
user8086643

Reputation:

Super method call with class name

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.

Upvotes: 0

Views: 393

Answers (3)

Simon
Simon

Reputation: 200

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

Upvotes: 1

ElDuderino
ElDuderino

Reputation: 3263

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.

Upvotes: 1

sam nikzad
sam nikzad

Reputation: 1360

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

Upvotes: 0

Related Questions