Java super related questions

Asked 2 years ago, Updated 2 years ago, 102 views

It's a question that suddenly came to mind while studying.

It seems that when you receive a producer of the super class, you use the distinction as the producer's variables

ex) If the producers of the parent class are Character (String name, intp) and Age (inage) in super(name, hp) and super(age) expressions.

So what if we get producers with different names but all the same variables?

ex)If Player (String name, intp) and Enemy (String name, intp) are in the parent class,
     In order to inherit from the lower class, you have to write super(name, hp) and super(name, hp)
     Don't you have a compilation error because you can't distinguish it like this?

And I would appreciate it if you could tell me how to inherit producers with different names but the same variable names at the same time.

java super

2022-09-22 19:28

2 Answers

Java is not provided with multiple inheritance.

Two direct parent classes cannot exist.

Eventually, super calls only one of the overloaded generators of a single direct inheritance class that matches the parameter type.


2022-09-22 19:28

Java supports only a single inheritance, and compilation errors occur if the method signatures of the constructors are the same. There are many contents that are difficult to understand the explanation or terms of the question, but the situation you asked does not occur in Java.


2022-09-22 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.