Java输出语句中缺少标识符怎么办?极悦小编来为大家举例说明。
将公有变量改成私有变量之后,增加两个构造函数,访问通过外部调用构造函数实现初始化赋值。
//程序文件名为 UseConstruct.java
public class UseConstruct
{
public static void main(String[] args)
{
Manager m = new Manager("王飞",10000,"业务部"); //初始化赋值
System.out.println(m.getSalary());
}
}
class Employee
{
private String name;
private int salary;
//构造函数
public Employee(String_name, int_salary)
{
name = _name;
salary = _salary;
}
public String getSalary()
{
String str;
str = "名字:" + name +"\nSalary:" + salary;
return str;
}
}
class Manager extends Employee
{
private String department;
//构造函数
public Manager(String_name, int_salary, String_department)
{
super(_name, _salary);
department = _department;
}
public String getSalary()
{
return super.getSalary() + "\nDepartment:" + department;
}
}
在两个构造函数处,参数声明格式错误String_name, int_salary, String_department
将 String_name, int_salary, String_department
改为 String _name, int _salary, String _department
你适合学Java吗?4大专业测评方法
代码逻辑 吸收能力 技术学习能力 综合素质
先测评确定适合在学习