Super constructor in java

Explain, please

public class Contact {
    private String contactId;
   private String firstName;
    private String lastName;
    private String email;
    private String phoneNumber;

public Contact(String contactId,String firstName, String lastName,   String email,        String phoneNumber) {
    super();  //what does standalone super() define? With no args here?
    this.firstName = firstName;  
    this.lastName = lastName;     //when is this used?, when more than one args to be entered?
    this.email = email;
    this.phoneNumber = phoneNumber;
}

Super () with no arguments inside means that there is more than one argument that needs to be defined? And is this done using "this.xxx"?

Why we define in the very "contact with the social class." Why did we define again and name his arguments here?

+3
source share
2 answers

Super () with no arguments inside means that there is more than one argument that needs to be defined?

No, it super()just calls the no-arg constructor of the base class, in your case Object.

. , , no-arg. , super() out, .

, super(), ? , no-arg. -, , , super("hello").

this.lastName = lastName; //when is this used?, when more than one args to be entered?

this.lastName = lastName; super(). , lastName - lastName.

public Contact(String contactId, String firstName, String lastNameArg,
               String email, String phoneNumber) {
    // ...
    lastName = lastNameArg;
    // ...
+7

super() (no-arg) . , , , .

super() - .

Object

+6

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


All Articles