Inheritance in Java
By: Top • Essay • 389 Words • January 27, 2010 • 885 Views
Join now to read essay Inheritance in Java
In Java programming, inheritance plays an important role in a programmer’s ability to reuse codes. Inheritance in basic terms allows a subclass to use the variables and methods of a superclass. When a programmer creates a subclass with new variables and methods, it can easily use the superclass’s methods and variables by extending without having to rewrite the entire superclass over again. Therefore, the subclass inherits variables and methods from the superclass. In this sense, inheritance helps save time in writing codes because imagine how time-consuming it would be to work with a superclass which had thousands of methods and variables. Needless to say, the time spent by the programming would be very costly if inheritance was not available.
Not only does inheritance saves programming time, it helps maintain efficiency and accuracy. If a programmer did not have the ability to use inheritance, they would have to rewrite the classes to add variables or methods and would increase the chances of creating errors. With thousands of variables and methods in a program, it can be easy to lose track or be inconsistent when editing changes.
An example used by Richard Baldwin helps illustrate how inheritance works. A superclass RADIO has attributes and methods of components of a car radio. When a new class is created to add tape player,