Studying how to use the constructor (java)

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

Studying how to use the constructor (java)
[Java] How to use the File class
[Java] How to use the hasNext function
[Java] How to use the toString () method
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Processing × Java] How to use the function
[Java] How to use the Calendar class
[Java] How to use Map
[Java] How to use Thread.sleep to pause the program
How to use java Optional
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java Map
How to use the replace () method (Java Silver)
How to use Java variables
[Java] How to use Optional ①
[Java] How to omit the private constructor in Lombok
How to use the link_to method
How to use Java HttpClient (Get)
How to use the include? method
How to use the form_with method
Studying Java # 6 (How to write blocks)
How to use Java HttpClient (Post)
[Java] How to use join method
How to use the wrapper class
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
Multilingual Locale in Java How to use Locale
How to use submit method (Java Silver)
[Rails] How to use the map method
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
How to install the legacy version [Java]
How to use Java Scanner class (Note)
How to get the date in java
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation
To use the "java" command line tool ... How to avoid popping up
The operator that was born to be born, instanceof (Java) ~ How to use the instanceof operator ~
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option