Object-Oriented Programming in a nutshell-part 2

In the most recent article published on the Rhapsody, the basic concept of Object-orientation with respect to Java was discussed. I also did a preliminary implementation of the OOP concepts using a Java class, a method as well as an object.

Today's article focuses on more Object-Oriented programming concepts with a view to understanding these horror terms: Inheritance and Abstraction

Abstraction

We kick off this interesting series with Abstraction. Literally, abstraction is the tendency to go with ideas rather than events. From an OOP-perspective, abstraction refers to the a process of hiding the implementation details from the user, thus only the functionality will be provided to the user. In other words user will have the information on what the object does instead of how it does it.

Inheritance

Using the most realistic intro to this word, I would simply say that Inheritance is the tendency of classes to inherit commonly used state and behavior from other classes. Doesn't make sense I know right? Ideally, the derived class inherits the states and behaviors from the base class. The derived class is also called subclass and the base class is also known as super-class. The derived class can add its own additional variables and methods. Typical example: A mountain bike, a road bike all share the characteristics of bicycles i.e: current speed, current pedal layout, current gear. Yet each also defines additional features that make them different: road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

In this example, Bicycle now becomes the superclass of MountainBike and RoadBike. dditionally, it is important to note that in the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses.

Now for the implementation of Inheritance. Given that we already know how to create a class, we will go ahead to create a sublcass. We do this using the extends keyword.
public class MountainBike extends Bicyce{ // new fields and methods defining // a mountain bike to go here }

This gives MountainBike all the same fields and methods as Bicycle. My next post aims to focus exclusively on the other two elements of OOP which are: Encapsulation and Polymorphism