HAS-A relationship
by , 04-26-2012 at 05:32 PM (3137 Views)
Such relationships are usage based. It shows whether a class consist of HAS-A, certain thing. Code duplication and bugs are reduced by this relationship.
For example:
Class Van HAS-A speed is shown. Speed’s separate class doesn’t require putting the complete code which has relation with speed, inside the Van class, that makes the reusage of speed class possible in various applications.Java Code:public class Vehicle{} public class Speed{} public class Van extends Vehicle{ private Speed sp; }
In object oriented features, there is no need to worry that which objects does real work. This can be achieved by hiding the implementation details of the Van class from Van class users.
Remember this fact that just one inheritance is supported by the Java. This shows it is not possible to extend more than 1 class. Hence, given below is not legal.
However, one or more interfaces can be implemented by a class.Java Code:public class extends Animal, Mammal{}









Email Blog Entry
License4J 4.0
Yesterday, 12:23 AM in Java Software