Object-Oriented Programming (OOP) is a programming language model organized around objects rather than actions and data. An object-oriented program can be characterized as data controlling access to code.
Concepts of OOPSÂ :
👉 Object
👉 Class
👉 Inheritance
👉 Polymorphism
👉 Abstraction
👉 Encapsulation
OBJECTÂ :
Object means a real word entity such as pen, chair, table etc. Any entity that has state and behavior is known as an object. Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. Objects can communicate without knowing details of each other’s data or code, the only necessary thing is that the type of message accepted and type of response returned by the objects.
An object has three characteristics:
đź“– state: represents data (value) of an object.
🎬 behavior: represents the behavior (functionality) of an object such as deposit, withdraw etc.
🆔 identity: Object identity is typically implemented via a unique ID. The value of the ID is notvisible to the external user. But, it is used internally by the JVM to identify each object uniquely.
CLASSÂ :
Collection of objects is called class. It is a logical entity. A class can also be defined as a blueprint from which you can create an individual object. A class consists of Data members and methods.The primary purpose of a class is to hold data/information. The member functions determine the behavior of the class, i.e. provide a definition for supporting various operations on data held in the form of an object.Class doesn’t store any space.
INHERITANCEÂ :
Inheritance can be defined as the procedure or mechanism of acquiring all the properties and behavior of one class to another, i.e., acquiring the properties and behavior of child class from the parent class. When one object acquires all the properties and behaviours of another object, it is known as inheritance. It provides code reusability and establishes relationships between different classes. A class which inherits the properties is known as Child Class(sub-class or derived class) whereas a class whose properties are inherited is known as Parent class(super-class or base class). Types of inheritance in java: single, multilevel and hierarchical inheritance. Multiple and hybrid inheritance is supported through interface only.
POLYMORPHISMÂ :
When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc.
Polymorphism is classified into two ways:
Method Overloading(Compile time Polymorphism)Â :
Method Overloading is a feature that allows a class to have two or more methods having the same name but the arguments passed to the methods are different. Compile time polymorphism refers to a process in which a call to an overloaded method is resolved at compile time rather than at run time.
Method Overriding(Run time Polymorphism)Â :
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in java.In other words, If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding.
ABSTRACTIONÂ :
Abstraction is a process of hiding the implementation details and showing only functionality to the user. For example: phone call, we don’t know the internal processing.In java, we use abstract class and interface to achieve abstraction.
ENCAPSULATIONÂ :
Encapsulation in java is a process of wrapping code and data together into a single unit, for example capsule i.e. mixed of several medicines.A java class is the example of encapsulation.