, . . Java . , . . , Employee Employee
public Employee(String n, double s, int year, int month, int day){ name=n;
salary=s;
hiredate=(new GregorianCalendar(year,month-1,day)).getTime();
}
, . , Employee, 1 . 31 2009 .
public Employee(String n){
name=n;
salary=1;
hiredate=(new GregorianCalendar(2009,12,31)).getTime();
}
, . , e1 e2 Employee. .
Employee e1 = new Employee(James Bond, 100000, 1950,1,1); Employee e2 = new Employee(James NeBond);
James Bond 1 1950 100000 .. ( e1), James NeBond 31 2009 1 .. ( e2), .. , - .
1.3. ,
(inheritance) - , ( ) ( ) . "/", . .
Employee . , . , . , , Employee , .
class Manager extends Employee{ // //
private double bonus; //
public Manager (String n, double s, int year, int month, int day){
super(n, s, year, month, day); // ..
//, -
// . ..
|
|
//super 5 ,
//Employee
}}
Manager 4 name, salary, hiredate, bonus. , () (). , , .
Employee Manager. , getSalary() . , , (overriding) . :
class Manager extends Employee{
.
public void getSalary() { .} // ()//
.
}
() :
public void getSalary(){
double basesalary=super.getSalary();
return basesalary+bonus;
}
(encapsulation) - (). - - . .
. , . , , . , .
(polymorphism) - , (, ) ( ) . , , , - .