本帖最后由 air 于 2013-11-9 16:11 编辑
主函数
{
Teacher t = new Teacher("XXX");
System.out.println(t.name+t.prelect)
//我这里如果要调用这两个数值并打印显示,但是因为private
我要在主函数中调用这个name.可是他是私有的,我要怎么定义一个set方法去调用它呢?
}
class Teacher
{
private String name;
private Computer cmpt;
Teacher(String name)
{
this.name = name;
cmpt = new Computer();
}
public void prelect()
{
cmpt.run();
System.out.println("讲课");
}
} |