[Java] Introductory structure Class definition Relationship between class and instance Method definition format

Output

What is a class? Class = field + method A method defines a process.

package javabase; // ← Package declaration class Staff {// ← template String name; int staffid; String email; }

Definition of 1 class public class StaffInfo {// ← Class definition

public static void main (String [] args) {// Method definition

Staff yamada = new Staff (); // ← Instantiation yamada.name ="Taro Yamada";

	System.out.println(yamada.name);

}

}

Create Java program = Create class

2 Relationship between class and instance // Class = template Taiyaki mold // Instance = The part Taiyaki generated from the template is the instance. // class Staff {// ← Staff class (template) // String name; // int staffid; // String email; //} // Staff yamada = new Staff (); // Mr. Yamada's instance (actual)

3 Method definition format

//クラスとは

//クラスX

// Store data Field A.B // Description processing method XYZ

// public class StaffInfo {// ← Class definition Declaration that the class will be defined from now on

// public static void main (String [] args) {// Method definition Med definition used in this class

//メソッドの定義 //public←アクセス修飾子

// public accessible from other classes // protected In the same package / inherited class // None Same package only //private

//メソッドの定義 // static ← Other modifiers

// abstract abstract class method // static Can be called directly from the class (not called from the instance) // final cannot be changed

//void // void Return type

//処理結果を繰り返す>返り値の型を定義

// Do not repeat the value> [void]

// main (String [] args) ← method name (argument) //メソッドを呼び出すときにパラメーターを渡す。 //パラメータ=引数 //カンマで複数渡せる

2 // Relationship between class and instance // Class = template Taiyaki mold // Instance = The part Taiyaki generated from the template is the instance. // class Staff {// ← Staff class (template) // String name; // int staffid; // String email; //} // Staff yamada = new Staff (); // Instance of Mr. Yamada (actual)

// 3 Method definition format

//クラスとは

//クラスX

// Store data Field A.B // Description processing method XYZ

// public class StaffInfo {// ← Class definition Declaration that the class will be defined from now on

// public static void main (String [] args) {// Method definition Med definition used in this class

//メソッドの定義 //public←アクセス修飾子

// public accessible from other classes // protected In the same package / inherited class // None Same package only //private

//メソッドの定義 // static ← Other modifiers

// abstract abstract class method // static Can be called directly from the class (not called from the instance) // final cannot be changed

//void // void Return type

//処理結果を繰り返す>返り値の型を定義

// Do not repeat the value> [void]

main (String [] args) ← method name (argument) Pass parameters when calling the method. Parameter = argument You can pass more than one with a comma

Method definition

public static void main(String[] args)

main method is

Can be called from other classes. Can be called directly from the class Has no return value It has an array type argument (parameter) called argas

Recommended Posts

[Java] Introductory structure Class definition Relationship between class and instance Method definition format
Difference between instance method and class method
[Java] Differences between instance variables and class variables
Java class definition and instantiation
Difference between class and instance
Relationship between package and class
Difference between instance variable and class variable
[Java] Relationship between H2DB and JDBC
[Ruby] Relationship between parent class and child class. The relationship between a class and an instance.
Easy to understand the difference between Ruby instance method and class method.
[Java] Inheritance and structure of HttpServlet class
[Java] Instance method, instance field, class method, class field, constructor summary
Ruby: Differences between class methods and instance methods, class variables and instance variables
Relationship between UI test and recording, implementation method
Java programming (class method)
Java programming (class structure)
[Java Silver] What are class variables instance variables and local variables?
[Java] Set structure of collection class (about HashSet and TreeSet)
What is the difference between an action and an instance method?
[Java] A class is an OS, and an instance is a virtual computer.
[Java] Difference between == and equals
Difference between variables and instance variables
Relationship between Controller and View
Java methods and method overloads
Search and execute method by name from instance with processing (java)
The relationship between strict Java date checking and daylight savings time
About the relationship between the Java String equality operator (==) and initialization. Beginners
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
Differences between "beginner" Java and Kotlin
[Java] Difference between Hashmap and HashTable
Difference between == operator and eqals method
[Java beginner] == operator and equals method
Relationship between database and model (basic)
StringBuffer and StringBuilder Class in Java
[JAVA] Difference between abstract and interface
Differences between Applet class and JApplet class
[Java] Difference between array and ArrayList
[Swift] Protocol concept and definition method
Differences between Java and .NET Framework
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
Java beginner escape boot camp Part 1 Java class structure and how to write
Interpret the relationship between Java methods and arguments into a biochemical formula
Activity transition with JAVA class refactoring and instance experimented on Android side