更新时间:2022-11-29 10:40:38 来源:极悦 浏览1100次
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
0基础 0学费 15天面授
Java就业班有基础 直达就业
业余时间 高薪转行
Java在职加薪班工作1~3年,加薪神器
工作3~5年,晋升架构
提交申请后,顾问老师会电话与您沟通安排学习