OOPs concept

Quick Reference :

  • EAPI – (Encapsulation, Abstraction, Polymorphism(Compile Time & Runtime), Inheritance)
  • Relationship
    • IS-A (Interface)
    • Has-A (Associated)
      • Composition (Object declared inside Object)
      • Aggregation (List of Objects inside Object)

  • OOP stands for Object Oriented programming
  • Before OOPs there were procedural programming where it was all about the functions and variables written into a single file. Where variables stored data and functions performed operations on that data.
  • After oops concept came up we divided the functions and variables into logical groups called class and started calling functions and variables as methods and properties respectively.

List of OOPs Concept in Java with Example

  • Baiscs
    • Classes – Logically Grouping of Similar Entities
    • Objects – Instance of classes
  • 4 Pillars
    • Encapsulation – Bundling data and methods into single unit (class/enums)
    • Abstraction – Looking at something without being concerned about the inner details
    • Polymorphism – one interface and have multiple implementations
    • Inheritance – Inheriting the properties of parent class is called inheritance
  • Relational Concept
    • Association
    • Aggregation
    • Composition
    • Coupling and cohesion


  • Encapsulation is the idea of bundling data and methods that work on that data within one unit. Eg class in java
  • Note : Lesser that number of arguments to the methods, better the code.
    ” The best functions are those with no parameters!” – Robert C Martin


  • Looking at something without being concerned about the inner details or mechanics.
  • Example : While Driving a car, person need not be concerned about what happens internally when you press a accelerator or a break but what he needs to know is which function to call to actually perform those operations.

Polymorphism (Many forms)

  • Polymorphism refers to a programming language’s ability to process objects differently depending on their data type or class.
  • Polymorphism allows you to define one interface and have multiple implementations
  • There are two types of polymorphism in java
    • Compile time polymorphism – Method overloading in Java
    • Run time polymorphism – Method overriding in Java

Inheritance (is – a – relationship)

  • Inheritance is a mechanism in which one class acquires the property of another class.
  • For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class.
  • Hence, inheritance facilitates Reusability and is an important concept of OOPs

Association (Has a relationship)

  • Aggregation (Weakly Coupled)
    • List<Employees> empList
    • Even if empList cease to exist both the class will survive
  • Composition (Stronglt coupled)
    • Employee class has a Department object inside it
    • Employee cannot exist without Department Object hence composition

Class diagram - Wikipedia

Others Benefits of java : Robust

  • One of the major advantages of Java over C++ is that it prevents memory leaks.
  • Java manages memory on its own and does garbage collection automatically.
  • Bad memory management in C++ is a big source of errors in programs.

Others Benefits of java : Secure

  • Java code runs inside the JVM.
  • This creates a sandbox that makes it hard for Java code to do evil things to the computer it is running on.

Reference :

Leave a Comment