造人计划
package com.aila;
public class La {
public int id;
public String name;
public int age;
public String city;
public void printX()
{
System.out.println("我的名字叫=" + name + ",代号是 =" + id + ", 年龄是=" + age + ", 所在城市=" + city);
}
//构造方法
public La()
{
System.out.println("这是没有参数的方法,用此语句证明执行过!");
}
//有参数构造
public La(int id,String name,int age,String city) {
this.name=name;
this.id=id;
this.age=age;
this.city=city;
}
}
package com.aila;
public class Ai {
public static void main(String[] args)
{
//开始造人啦
La aila1=new La();
aila1.name="xiaohan1";
aila1.id=001;
aila1.age=18;
aila1.city="秋叶原";
La aila2=new La();
aila2.name="xiaohan2";
aila2.id=002;
aila2.age=18;
aila2.city="秋叶原";
La aila3=new La();
aila3.name="xiaohan3";
aila3.id=002;
aila3.age=18;
aila3.city="秋叶原";
aila1.printX();
aila2.printX();
aila3.printX();
}
}