How super () works in the constructor

I have a quick question regarding how super () is used in the constructor. I know the basics of how he will call the superclass, but I recently looked through some code and don’t understand how it is used in this example. Here is the essence of the part that bothers me:

public class MyClass implements MyInterface {
    String myString = null;

    public MyClass() {
        super();
    }

    public MyClass(String A) {
        super();
        myString = A;
    }

    public interfaceMethod {
        // this is the method from MyInterface
    }
}

I understand how constructors are used, and that’s it, but I just don’t see the point in super () methods. Is it related to the interface it implements? I thought super () was used if the class extends something? Did I miss some basic java knowledge here? Any help for noob would be greatly appreciated. Thank!

+4
source share
4 answers

super() java.lang.Object, Object

+3

java java.lang.Object , Object ( ).

+1

, , ( ), super() . , , , super ( ). , super(), .

0

java java.lang.Object.

, class A - class A extends Object.

,

class A extends B {}

class B extends Object {}
class A extends B {}

, , . , Object. , super() . , super().

, MyClass - , , super() , Object. MyClass String, , super() , Object.

, .

0
source

Source: https://habr.com/ru/post/1546024/


All Articles