Very often people trying to give examples about inheritance create confusion about the relationship between 'Object and Class' and the relationship between 'sub class and super class'. For example, I recently observed an article at http://java.sun.com/developer/technicalArticles/wombat_world/ which gives an example of inheritance as
public class Jane extends Person {...}The relation between Jane and Person is more observed as Jane being an instance of Person, and not Jane being a sub class of Person, as is being implied by the example. The class is like a template using which instances can be created. A sub class is also a class, and so it is also a template which either inherits or overrides methods defined in the super class. A better example to show inheritance would be something like
public class ShopKeeper extends Person {...}
2 comments:
Correct Pravin,
We have simple rule of thumb. Any thing which is (viewable, *able) is an object, of some abstraction, in this case Jane is a object of an abstraction called Person / Shopkeeper.
So we call class as an abstract data type.
:-)
>>So we call class as an abstract data type.
Not only class but all data types in a higher level programming language are abstract types.
"The fundamental idea of an abstract data type is that the use of a type is separated from the representation and set of operations on values of that type." - Robert W Sebesta from his book Concepts of Programming Languages
Post a Comment