Principles of Object-Oriented Programming

Object oriented programming is based on the following principles.

  • Class
  • Object
  • Inheritance
  • Encapsulation
  • Abstraction

We will briefly discuss each of these principles in this section. In the next few chapters we will learn about them in detail with their applications in Java.

Understanding Classes

A class is a collection of objects of similar type. Once a class is defined, any number of instances can be created which belong to that class.

The class is at the core of Java. It defines the shape and nature of an object. Any concept you wish to implement in a Java program must be encapsulated within a class. In fact, the next few chapters are dedicated to classes and the components that go with it.

Understanding Objects

Objects are the basic runtime entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code.

Understanding Inheritance

Inheritance allows a class to derive features of another class. The existing class is called the base class, superclass, or parent class. The new class is called the derived class, subclass, or child class.

When a class inherits, the members of the parent class are derived. You can change their behavior, or just use them as is it is. You can extend the behaviour of the parent class.

Understanding Abstraction

Abstraction refers to representing essential features without including the details or explanations.

For example, both a Lamborghini and Ferrari have steering wheel and accelerator. Internally, the mechanisms for steering and acceleration are different but anybody who knows to drive a car can drive both the cars without having to worry about the internal details.

Understanding Encapsulation

This section will be added shortly.

Understanding Polymorphism

Polymorphism refers to the ability to take more than one form.

Here is a real life example of polymorphism, where a person can have different characteristics based on the viewers perspective. Consider a woman who is a mother, an actress, and owns a bank account. As you can see, the same person posses different behavior from different perspectives. This is called polymorphism.

Polymorphism is an important feature of Object Oriented Programming (OOP).