# Inheritance vs Subtyping

• Inheritance goes together with subtyping
• But they are orthogonal ideas
• Inheritance relationship between two classes does not imply subtype relationship
• Subtyping is a relation between (object) types
• Object (types) refer to the interface (which methods are available)
• Subtyping is interface sharing
• A type B is a subtype of A if every function that can be invoked on an object of type A can also be invoked on an object of type B
• Inheritance is a relation between classes
• Classes refer to the implementation
• Inheritance is code sharing
• A type B inherits from another type A if some functions for B are written in terms of functions of A
• Connection: A subclass generates objects whose type is a subtype of the objects generated by a superclass