06
Jan
Object-Oriented Design with UML and Java giving it
Object-Oriented Design with UML and Java giving it a value of 3000. In both cases the method for getMonthlySalary executed is defined in the Employee class. // class Employee public int getMonthlySalary() { return theMonthlySalary; } // method: getMonthlySalary However, we might also have: programmer.setLanguage( Java ); which sets the attribute theLanguage to a value of Java . The method for setLanguage executed is defined in the Programmer class as: // class Programmer public void setLanguage(String aLanguage) { theLanguage = aLanguage; } // method: setLanguage Note that: employee.setLanguage( Java ); is illegal. An Employee cannot respond to the message setLanguage as it is not declared in the Employee class. Clearly the construction of a subclass object must involve the use of a constructor declared in its class. However, a subclass constructor method may also make use of its superclass constructor. For example, we have: // class Employee public Employee(int aPayrollNumber, int aMonthlySalary, String aName) { thePayrollNumber = aPayrollNumber; theMonthlySalary = aMonthlySalary; theName = aName; } // method: Employee and // class Programmer public Programmer(int aPayrollNumber, int aMonthlySalary, String aName, String aLanguage) { super(aPayrollNumber, aMonthlySalary, aName); theLanguage = aLanguage; } // method: Programmer Notice the use of the reserved word super in the Programmer constructor method that refers to the immediate superclass. This is how its superclass constructor with three parameters (an int, an int and a String) is executed. It is important to understand that even though two constructors are used in the construction of a Programmer there is only one object created. It is a Programmer not a Programmer and an Employee.
For high quality jboss hosting services please check jboss web hosting website.
