"Java Combat Development classic" chapter fifth 5.5

Source: Internet
Author: User

Package five;

public class Five {
public static void Main (string[] args) {
User P1=new user ();
P1.tell ();
User P2=new User ("XPQ");
P2.tell ();
User P3=new User ("Xpq", "mima123");
P3.tell ();
}
}
Class user{
Private String UserName;
private String password;
private static int num; Use the static property to count how many instantiated objects a class produces
Public User () {//define no parameter construction method
num++;
};
Public User (String userName) {//define single parameter construction method
num++;
This.username=username;
}
Public User (String username,string password) {//define double-parameter construction method
num++;
This.username=username;
This.password=password;
}
Public String GetPassword () {//method to get the password
return password;
}
public void SetPassword (String password) {//How to set the password
This.password=password;
}
public void Tell () {
System.out.println ("User named" +username+ "corresponding password is" +password+ "the number of users is" +num);
}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Java Combat Development classic" chapter fifth 5.5

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.