Calling super() in inheritance — Java

LIU YONGLIANG
4 min readFeb 26, 2021
Photo by Sincerely Media on Unsplash

P.S. Finally back with another quick article on something that I learned during (yet another) late-night discussion.

Motivation

While browsing through the codebase of a brownfield project that I am currently working on as part of my school work, I found the following lines weird at a glance.

public class StorageManager implements Storage {
// other details omitted ...
public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) {
super();
this.addressBookStorage = addressBookStorage;
this.userPrefsStorage = userPrefsStorage;
}

The above code belongs to a concrete implementation of an interface named Storage and the particular line that I was interested in is this: super();.

Reasons why I felt that the call to super was unusual:

  1. StorageManager does not extend from any parent class, so I supposed calling super means calling the Object constructor, why would one ever do that?
  2. If somehow the call to super is related to the interface that StorageManager is implementing, it makes no sense because interfaces cannot be instantiated anyway.
  3. While I knew that calling super invokes the parent constructor and one could use it to pass…

--

--

LIU YONGLIANG

Computer Science Student @ National University of Singapore. Connect with me @ https://www.linkedin.com/in/-yong-/