10.23造人类;this关键字

1.

package cn.dede.w;

public class Demoperson {

public static void main(String[] args) {
// TODO Auto-generated method stub
Persondemo p1=new Persondemo(001,"MC刘备",43,"北京","定要到崂山去学仙!");
Persondemo p2=new Persondemo(002,"MC关羽",35,"北京","定要到崂山去学仙!");
Persondemo p3=new Persondemo(003,"MC张飞",48,"北京","定要到崂山去学仙!");
Persondemo p4=new Persondemo(004,"MC诸葛亮",25,"北京","定要到崂山去学仙!");

System.out.println(p1.introduce());
System.out.println(p2.introduce());
System.out.println(p3.introduce());
System.out.println(p4.introduce());

}

}

2.E2

package cn.dede.w;

public class Persondemo {
public int id;
public String name;
public int age;
public String city;
public String songs;
public String introduce() {
return "我是" + id + "号, 叫 " + name + ", 今年" + age + "岁了, 来自" + city + " a ~ " + songs;
}
public Persondemo(int id,String name,int age,String city,String songs) {
this.id=id; //this关键字,表达的含义是当前对象 .表示当前对象的某个调用
this.name=name;
this.age=age;
this.city=city;
this.songs=songs;

}
}

 

posted @ 2017-10-30 13:44  土豆土豆你才是马铃薯  阅读(132)  评论(0编辑  收藏  举报