Class person // defines a person class {private int age; // declares the class attributes. Note that the type is privateprivate string name; person (int A) // default constructor, assign {This. age = A; // This is the current object} person (string N) // The default constructor assigns the initialization value {This. name = N;} person (int A, string N) {This. age = A; this. name = N; // reload the constructor to assign an initial value to age and name} public void speak () // define the class method, and print the name and age {system. out. println ("name =" + name + "age =" + age);} public Boolean compare (person p) // defines the method for comparing age of person {return this. age = P. age ;}} class persondemothis // main function {public static void main (string [] ARGs) {person p1 = new person (20, "xiangming "); // declare three person persons P2 = new person (18, "Xianggang"); person P3 = new person (19, "xianghong"); p1.speak (); // print the information of three persons (p2.speak (); p3.speak (); system. out. println (p1.compare (P3 ));}}
Experience: a small mistake lies in the uppercase letter of the string character type in Java