Since we make the instance variables private in order to implement Encapsulation, When implementing inheritance do we have to define even though the same, instance variables in the subclass or what is the recognized custom?
as always it depends on what you're planning to do. In very rare cases you will make the variables in the super class protected instead of private and let overriding classes use them directly. If you allow access through getters and setters, your overriding classes can use these methods. Alternatively, you could implement all state and behavior regarding those variables by an abstract class and let other classes extend the abstract class. Another approach is to use delegation instead of inheritance. Implement the state and behavior associated with the variables by a class and let other classes use this one for state manipulation. Re-defining the variables in overriding classes could also be a valid choice. However, as stated before, the design choice should depend on a specific problem/task.
Hope this helps, Thomas
SCJP 5.0, SCJD in progress
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: When implementing inheritance do we have to define instance variables