2013年12月15日星期日

Code doubt

package thirsty;
/ * If we need to staff in the development of a modeling system , the staff includes three attributes : name, job number and wages. Staff manager also contains, in addition the staff
* 's properties, as well as a bonus another property . Please use the inherited class thinking design staff and managers category. Asked the class to provide the necessary property access methods .
** /
public class Test2 {
public static void main (String [] args) {
/ / Manager manager = new Manager ("zhang", "JL01", 5000,10000);

}



/ / (1) the definition of employee class properties
abstract class Employee
{
private String name;
private String id;
private double salary;

/ / (2) to employees class attribute initialization
Employee (String name, String id, double salary)
{
this.name = name;
this.id = id;
this.salary = salary;
}

/ / (5) this time thinking : employees and managers need to work , but they are doing it are the same ?
/ / 1. ordinary employees and managers do things is different , the manager is not in one of the general staff ,
/ / 2. employees divided into ordinary employees and managers ,
/ / 3. This is not specifically describe things that are abstract
public abstract void work ();
}
/ / (7) thinking: If employees subdivision can be decomposed into an ordinary employee
/ / so the definition of an ordinary employee class inherits class staff
class CommonPerson extends Employee
{
CommonPerson (String name, String id, double salary)
{
super (name, id, salary);
}
/ / (8) but also because of the general staff of a company , he must work , it must be overwritten work () method
public void work ()
{
System.out.println ("commonperson work!");
}
}
/ / (3) the definition of the class manager
class Manager extends Employee
{
private int bonus;
/ / (4) initializes the class attribute to employees
Manager (String name, String id, double salary, int bonus)
{
super (name, id, salary) ;/ / inherit the parent class Employee
this.bonus = bonus;
}
/ / (6) because the manager of a company is also , he must work , it must be overwritten work () method
public void work ()
{
System.out.println ("manager work!");
}
}
}

this code Manager manager = new Manager ("zhang", "JL01", 5000,10000); This sentence has to ask the question how the solution ?
------ Solution ---------------------------------------- ----
inner class instantiation problem :
Manager manager=new Manager("zhang","JL01",5000,10000);
changed
 Test2.Manager manager=new Test2().new Manager("zhang","JL01",5000,10000);
on ok
------ For reference only -------------------------------- -------



public class Test2 {
public static void main(String[] args) {
 Manager manager=new Manager("zhang","JL01",5000,10000);
}
        //吧这里的东西都放到下面去就行了
}

这里放你的那些类


没有评论:

发表评论