I don't know how to use the constructor. It's studying.
[Knowing] ・ The name is the same as the class name ・ The role of initializing something (something is only vaguely known) ・ Super calls the constructor of the parent class · This calls the constructor of its own class -When using a variable with the same name as the argument, `` `this.str = str``` (the str on the left is the one you just defined, the str on the right is the argument of the method)
[What I don't understand] ・ How to use the constructor ・ Description method
[What I found out] ・ The constructor is a class ・ Return value cannot be set ・ Arguments can be set -Initialize member variables (variables outside the method in the class)
sample.java
public class sample{
int num; //← This
String name; //← This is also
public sample_method(){
~~~~
~~~~
}
}
I wonder if it looks like this. Next, let's write the code and study the implementation flow concretely.
Recommended Posts