Home > Back-end >  For help on Java inheritance question... The couple
For help on Java inheritance question... The couple

Time:09-29

Today to write the code is the one always shows no enclosing the instance of the error, and thought for a long time don't know how to change for help
The import c10. PrintMessages. Manager. Director;

Public class PrintMessages {
Public static void main (String [] args) {
During the xiaoli=new during (0001, "xiao li", 5222); -- -- -- -- -- - the error place
During the xiaozhang=new during (0002, "zhang", 3500);
During the xiaohei=new during (0003, "black", 3500);
Manager xiaoliu=new Manager (0004, "liu", 5000, "Java");
Manager xiaoqiang=new Manager (0005, "small strong", 8000, "IT");
Director xiaoyuan=new Director (0006, "small circle", 10000, "400");
System. The out. Println (xiaoli. ToString ());
System. The out. Println (xiaozhang. ToString ());
System. The out. Println (xiaohei. ToString ());
System. The out. Println (xiaoliu. ToString ());
System. The out. Println (xiaoqiang. ToString ());
System. The out. Println (xiaoyuan. ToString ());
}


The class Employee {
Private long number;
Public String name;
Private double salary;

Public Employee (long number, a String name, double salary) {
super();
This. Number=number;
this.name=name;
This. Salary=salary;
}

Public String getDetail () {
Return this. ", "+ number + enclosing the name +", salary: "+ this. Salary;
}
}

The class during the extends the Employee {

The public during the (long number, a String name, double salary) {
Super (number, name, salary);
}

Public String getDetail () {
Return super. GetDetail ();
}
}

The class Manager extends the Employee {
Private String department="software development";

Public Manager (long number, a String name, double salary, String dep) {
Super (number, name, salary);
This. The department=dep;
}
Public String getDetail () {
Return super. GetDetail () + ", management department: "+ enclosing department;
}

The class Director extends the Employee {
Private String most egregious nest-feathering="400";

Public Director (long number, a String name, double salary, String most egregious nest-feathering) {
Super (number, name, salary);
This. The most egregious nest-feathering=most egregious nest-feathering;
}

Public String getDetail () {
Return super. GetDetail () + ", subsidies: "+ this. Most egregious nest-feathering;
}
}
}
}

CodePudding user response:

The program inside the Employee with the Employee is the inner class oh, all wrapped in PrintMessages within the code, if you intended to not make the inner class can try to put this a few code from PrintMessages {} to move out of this class

CodePudding user response:

reference 1st floor weixin_44287924 response:
this program inside the Employee with the Employee is the inner class oh, all wrapped in PrintMessages within the code, if you intended to not make the inner class can try to put this a few code from PrintMessages {} to move out of this class

Thank you very much! Has been solved,
  • Related