找测试程序的错误 java
packagecharper9;publicclassTest1{publicstaticvoidmain(String[]args){Staffstaff1=newSt...
package charper9;
public class Test1{
public static void main(String[] args){
Staff staff1=new Staff("Tom","湖南长沙","07315623456","12345@qq.com","长沙理工大学",2475);
System.out.println(staff1.toString());
Person staff2=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
System.out.println(staff2.toString());
System.out.println(staff2.getStaffId());//是否会出错?
System.out.println(staff2.getCompany());//是否会出错?
System.out.println(staff2.getName());//是否会出错?
Employee staff3=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
System.out.println(staff3.toString());//调用的是哪个类的toString()方法?
System.out.println(staff3.getStaffId());//是否会出错?
System.out.println(staff3.getCompany());//是否会出错?
System.out.println(staff3.getName());//是否会出错?
}
} 展开
public class Test1{
public static void main(String[] args){
Staff staff1=new Staff("Tom","湖南长沙","07315623456","12345@qq.com","长沙理工大学",2475);
System.out.println(staff1.toString());
Person staff2=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
System.out.println(staff2.toString());
System.out.println(staff2.getStaffId());//是否会出错?
System.out.println(staff2.getCompany());//是否会出错?
System.out.println(staff2.getName());//是否会出错?
Employee staff3=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
System.out.println(staff3.toString());//调用的是哪个类的toString()方法?
System.out.println(staff3.getStaffId());//是否会出错?
System.out.println(staff3.getCompany());//是否会出错?
System.out.println(staff3.getName());//是否会出错?
}
} 展开
2个回答
2011-03-24
展开全部
你写的类型是不是有问题了
追问
可能,我不知道,刚学
追答
奥!
你看看这两个有什么区别了
Employee staff3=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
Person staff2=new Staff("Kate","山东济南","05315623456","12345@qq.com","空军部队",1563);
都是采用的多态吗?他们的内容是一样的!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询