Inheritance and Access control in Java

Different kinds of objects often have a certain amount in common with each other.Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. By creating subclasses, we can inherit both variables and methods from other classes; this encourages code reuse. Method overriding is another code reuse feature. Related to the idea of inheritance are the concepts of abstract classes, interfaces, and inner classes.

For Example:

Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

No comments:

Post a Comment