为什么这个java程序编译失败
classPerson{Stringname="Noname";publicPerson(Stringnm){name=nm;}}classEmployeeextends...
class Person {
String name = "No name";
public Person(String nm) { name = nm; } }
class Employee extends Person { String empID = "0000";
public Employee(String id) { empID = id; } }
public class EmployeeTest {
public static void main(String[] args) { Employee e = new Employee("4321");
System.out.println(e.empID);
}
} 展开
String name = "No name";
public Person(String nm) { name = nm; } }
class Employee extends Person { String empID = "0000";
public Employee(String id) { empID = id; } }
public class EmployeeTest {
public static void main(String[] args) { Employee e = new Employee("4321");
System.out.println(e.empID);
}
} 展开
3个回答
2014-09-17
展开全部
Employee 中的empID是非public声明(默认为protected),不能直接在外面访问(e.empID)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在这句话里面增加一点:
public Employee(String id) { empID = id; }
改为:
public Employee(String id) { super("No name"); empID = id; }
public Employee(String id) { empID = id; }
改为:
public Employee(String id) { super("No name"); empID = id; }
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询