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