Go directly to the code.
1 classLesson4ab2 //The public -decorated method under the same class, A, B, can call each other3 {4 Public voidA ()5 {6B ();//equivalent to this. B ();7 }8 Public voidB ()9 {TenA ();//equivalent to this. A (); One } A } - classlesson4c - //methods for public modification that exist in different classes C Call B the { - Public voidC () - { -Lesson4ab lab=Newlesson4ab (); + lab.b (); - //the top and bottom two methods are equivalent and can be called + NewLesson4ab (). B (); A } at } - classLESSON4DE - //static methods in the same class call each other with non-static methods. - { - Public Static voidD ()//modify with static, belong to class member - { in //E ();//Error: Unable to reference a non-static method from a static context E () - //"Popular saying is static does not refer to non-static" to + //This . E ();//Error: Unable to reference the non-static variable from the static context this - //"The popular saying is static and this cannot coexist" the * NewLESSON4DE (). E ();//through $ //Public void E () does not have a static decoration, belongs to an object, and can only be invoked with an objectPanax Notoginseng } - Public voidE ()//No static modifier, belongs to Object the { +D ();//equivalent to this. D (); A //object can invoke a class member the } + } - classLesson4 $ { $ Public Static voidMain (string[] args) - { -System.out.println ("May happy!"); the } -}
I am a small rookie, the above for online self-study experience summary, if there are errors please point out. Novice children shoes A lot of exchanges, the great God of many guidance. I wish you all a happy life.
Several simple call relationships and methods of "Java Foundation"