10.23 homework: Liu huihui, 10.23 homework: Liu huihui
Package cn. person. www; public class Prson {public int id; public String name; public int age; public String city; public String introduce () {return "I am" + id +, name: "+ name +", this year "+ age +" years old, from "+ city;} public person (int id, String name, int age, String city) {this. id = id; // this keyword, which indicates the current object. this indicates a call of the current object. name = name; this. age = age; this. city = city ;}}
Package cn. person. www; public class Demoperson {public static void main (String [] args) {// TODO Auto-generated method stub person p1 = new person (001, "Liu Bei", 40, "Beijing"); person p2 = new person (002, "Guan Yu", 37, "Beijing"); person p3 = new person (003, "Zhang Fei", 45, "Beijing"); person p4 = new person (004, "Zhuge Liang", 25, "Beijing"); System. out. println (p1.introduce (); System. out. println (p2.introduce (); System. out. println (p3.introduce (); System. out. println (p4.introduce ());}}