Java-this application

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.