Class method,
The class method belongs to all object instances in the following format:
Access modifier static data return type method name (){}
Non-static variables cannot be accessed in class methods. Use class name. Class method name or object name. Class Method Name
Define a student class and count how much money students have paid?
Public class StuDemo {public static void main (String [] args) {Student stu1 = new Student (29, "aa", 365); Student stu2 = new Student (29, "bb", 360); System. out. println (stu2.getTotalFee () ;}// Student class Student {int age; String name; int comment; static int totalFee; public Student (int age, String name, int comment) {this. age = age; this. name = name; totalFee + = fee;} // returns the total tuition fee [This is a static method] // class variables are used in principle to access and operate public static int getTotalFee (){
Return totalworkflow ;}}
Class methods are class-related and public methods.
The instance method belongs to each object's individual method.
Class methods can be directly accessed by class name. Class Method Name