62,621
社区成员
发帖
与我相关
我的任务
分享
class Panda
{
int id;
String naem ;
public Panda()
{
//.................
}
public Panda(int id,String name)
{
this.id=id;
this.name=name;
}
//实现了构造函数的重载
}
class TestPanda
{
public statci void main(String[]args)
{
Panda p1=new Panda();//调用无参构创建对象,它的属性未被赋值
p1.id=100;//给id赋值
p1.name="小小";//给name赋值
Panda p2=new Panda(200,"大大");//调用两参的构造函数,在创建对象的时候就赋值了
//而且是必须的
}
}