JAVA-Object-Oriented Programming

Ace Mourya
3 min readJul 4, 2021

--

OOP’s:

Java is an object-oriented programming language. Where bind the data and function together. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming.

Class:

Class is a collection of similar types of data of properties and behaviors.

Object:

An Object is an identifiable entity with some characteristics and behavior.

Inheritance:

A class to derive properties and characteristics from another class is called Inheritance.

  • Sub Class: The class that inherits properties from another class is called Sub Class or Derived Class.
  • Super Class: The class whose properties are inherited by sub-class is called Base Class or Super Class.

Types of Inheritance:

Diagrams

Single Inheritance:

A single child class that inherits properties from one parent class.

In the above diagrams: Class A is a base class that is derived from class B. It is also known as single-level inheritance.

Multilevel Inheritance:

Child or Derived class inherits properties of the superclass and this child class acts as a superclass for another derived class.

In the above diagrams: Class A is a base class that is derived from class B and this class B act as a superclass also inherited by class C

Hierarchical Inheritance:

A child class inheritance from more than one class.

In the above diagrams: Class A inherited by class B, class C, class D.

Multiple Inheritance:

More than one class is inherited by a single class.

In the above diagrams: Class A and Class B are inherited by a class B.

Hybrid Inheritance:

This inheritance is implemented by combining more than one type of inheritance. like: Hierarchical Inheritance and Multiple Inheritance.

In the above diagrams: Class A is the base inherited by subclasses B and C. And, class D inherits both the classes B and C.

Polymorphism:

Polymorphism means many forms. Same function name (but different signatures) being uses for different types or with different functionality.

Compile-time polymorphism: It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator overloading. But Java doesn’t support Operator Overloading.

Method overloading: Multiple functions with the same name but different parameters in a class. These functions are the different numbers of arguments or and diffrent in type of arguments.

Runtime polymorphism: It is also known as dynamic polymorphism. This type of polymorphism is achieved by the overridden method is resolved at Runtime.

Method overriding: Function with the same name defined in the parent class and child class in inheritance. That base function is said to be overridden.

Abstraction:

Abstraction is the property by which only the essential details are displayed to the user.

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

Encapsulation:

Encapsulation wrapping up of the data (variables) and code acting on the data (methods) together as a single unit.

--

--