OBJECT ORIENTED PROGRAMMING

Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.

OOPs Concepts:

Object:

Object is State and Behaviour.

It is a basic unit of Object Oriented Programming and represents the real life entities. 

Example: Fan(Color-State)

(Rotates-Behaviour)

Class:

A class is a user defined Blueprint or Template from which objects are created.  

Example:

public class Library{

}

Encapsulation:

Encapsulation means Protection or Data Binding.

Encapsulation can shared the information to limited people only.

  • Technically in encapsulation, the variables or data of a class is hidden from any other class and can be accessed only through any member function of own class in which they are declared.
  • As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.

Inheritance:

An Object of One Class Behaving to an Object of Another Class.

 Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in perl by which one class is allowed to inherit the features(fields and methods) of another class.
Important terminology:

  • Super Class: The class whose features are inherited is known as superclass(or a base class or a parent class).
  • Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods

Polymorphism:

Polymorphism means same method but different arguments.

Poly means Many and Morphing means Faces.

We can perform polymorphism in java by method overloading and method overriding.

If you overload a static method in Java, it is the example of compile time polymorphism. Here, we will focus on runtime polymorphism in java.

Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an overridden method is resolved at runtime rather than compile-time.

Abstraction:

Abstraction is a process of hiding the implementation details and showing only functionality to the user.

Data Abstraction is the property by virtue of which only the essential details are displayed to the user. The trivial or the non-essentials units are not displayed to the user.

Ex: A car is viewed as a car rather than its individual components.

Interface:

Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, no body).  

  • Interfaces specify what a class must do and not how. It is the blueprint of the class.
  • An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.

Leave a comment

Design a site like this with WordPress.com
Get started