Java always consists of classes. The process is written in the method in the class. In the method, the original operation and processing are written in the method called the main method.
The main method is written as follows. Let's name the class Test class according to the naming rule.
public class Test(){
public void main(String[] args){
/*
*Contents of main method processing
*The original operation is written here.
*/
}
}
here
public static void main(String[] args)
Please remember how to write. By the way, static between public and static is called a static clause and is attached to a method or variable. The detailed meaning is not mentioned here.
It seems that there is a meaning and it became such a rule, but I think that it is not necessary to pursue it so much. However, please understand that it is a normal method writing method.
Now, let's use the MultipleIntegerNumber method of the Calculate class in the main method of this Test class. This method
public class Calculate {
public int multipleIntegerNumber(int num){
num = 3*num;
return num;
}
}
is.
To use a class, first instantiate the class.
Calculate cal1 = new Calculate();
This cal1 is called an instance.
Then call the method.
cal1.multipleIntegerNumber(3);
That way, the method will return a return value of 9 as a result.
Recommended Posts