Friday, July 27, 2018

Understanding Object Oriented Concepts - OOPS

OOPS is the programming methodology that given an approach to deal with real life complex problems such as maintaining student’s data, banking operations, hospital management, inventory system and so on. 

Simula was the first Object Oriented language in the late 1960s. Java, C++ are known examples of Object oriented languages.

Except oops methodology there are some other methodologies available such as Procedural and Structured methodologies. To know more about these methodologies, please click on the link.  Programming Methodologies

In this chapter you I will discuss on object, class and OOPS features, in next chapters we will explore each feature of OOPS in detail. 

1 - Object

2 - Class

3 - Encapsulation

4 - Abstraction

5 - Polymorphism

6 - Inheritance


Object is an entity. Entity means anything about we are talking for example  - a pen, a car or a student , a Shop-Store anything. 

Every entity contains information about itself and what it does. In oops methodology entity is known as an object,  information about entity is known as properties of an object and 
work done by entity is known as functions of an object.

For example : - Student is an entity/object , his/her name,address,phone-no are the information/ properties of the student and study, play, exercise are the work/functions done by students.

Other example -Dog is object , its name, color, breed are its properties and barking,eating are its functions. 

Given diagram shows the properties and functionality of an object student.

Defining Object
Introduction of Object.

Class is the blueprint of any object. Blueprint means a representation of the object.

Class comes in picture when we talk about programming in oops. Any object's information and properties defines within a block called class of the object. Class is also known as datatype of an object. Object takes memory space but class does not take any space in memory.

To understand class better let's take an example, I want to maintain the student's data so that we will create a block for object by using class keyword. class is the area that will define object's properties and functions.

Syntax :

class Object_Name {

      Object Properties :

      Name, Address , PhoneNo

      Object Functions :

      Study, Play, Excercise


Wrapping object’s properties and functionality in a single unit is called encapsulation. Java class is the example of encapsulation.

Let's understand with example ...

class Customer {

      public String customer_name;

      public String customer_address;

      private String account_no;

      protected void deposit() {  }

      private void balance() {  }

As you can see Customer is an object, I have defined object's properties and functions into a class body i.e. class is wrapping object's information. .

Encapsulation also provides "hiding mechanism" i.e. programmer can maintain object's accessibility using access modifiers.

ex: public, private, protected, Java provides one more additional modifier is called default.

public     :  
Object's data can be accessible from anywhere  

private    :  
Object's data can't be accessible

protected :  
Object's data can be accessible only for those who are associated with object ex: one branch of bank can access another branch's data because they are associated with each other.

Will discuss in detail on access modifiers in Inheritance topic.
Click here to know about "Access Modifiers" 


Abstraction is  one of the important feature of object oriented languages because it hides the implementation from user and only provides functionalities to use.

In simple words we buy products online , create email account , recharge mobile online etc. we use functionalities but we don't care about how it is happening (the coding or implementation behind) is called abstraction.

While programming in object oriented languages like C++,Java etc. abstraction can be achieved by abstract classIn Java there is interface concept as well.

Through this link you can learn about abstraction and interface in detail, their usage in programming, difference between abstract class and interface etc.
     "Abstraction And Interface" .


Polymorphism is the another oops concept. It gives the functionality to use one task in different ways. Poly means many and morphism means forms. 

For example Object Shape has function to drawingShape.

If user tells circle's specifications then circle shape will be drawn,if user tells square's specifications then square shape will be drawn. 

This is polymorphism where one task drawingShape performs different operations as per the given specifications.

class Shape {

      drawingShape( Square specification arguments ) {

             "Drawing Square Shape"


      drawingShape( Circle specification arguments ) {

            "Drawing Circle Shape"


note : Its not a programming code, i used some programming syntax from C++ or Java to make you understand.

Polymorphism can be understand in two ways "CompileTime" and "RunTime" polymorphism. 

Compile-Time can be achieved by method-overloading and Run-Time can be achieved by method-overriding mechanism.

Through this given link you may also understand static and dynamic binding in polymorphism. Click here to know about polymorphism   


Inheritance is another important concept of OOPS. Inheritance provides re-usability feature, It allows that one object can share its data (properties and functions ) with another object.

For example one object Customer has properties name and address and check balance function.Now two different objects Mobile and Bank want to use same properties and functions for itself.

Through inheritance feature Customer object can share its properties and function to both objects.

The extends keyword use in C++/Java for inheriting objects, if A extends i.e. A object using properties of B object.

class Customer {


      checkBalance() {



class Mobile extends Customer {

      checkBalance() {

      name = "X"

      address = "Address1"

      print "checking balance for Mobile"



class Bank extends Customer {

      checkBalance() {

      name = "Y"

      address = "Address2"

      print "checking balance for Bank"



note : Its not a programming code, i used some programming syntax for better understanding. This example shows re-usability of Customer's object properties and functions.

There is a child and relationship between objects, Customer object is known as Parent and Mobile and Bank are the child of Customer object. Parent class known as Base class and child class known as derived class. 

Through this link you can learn different type of inheritance, Diamond problem, why java does not support multiple inheritance etc.
Click here to know more about inheritance 

Inheritance description

OOPS Concepts - Inheritance.
Thanks for reading, please do share and comment your suggestions.

1 comment: