Before going to do coding in apex once recall the basics of object oriented programming (OOP) language concepts.
What is OOPs :-
OOP (Object Oriented Programming) is a methodology, that provides a way of modularizing a program by creating partitioned memory areas for both data and methods that can be used as templates for creating copies of such objects (Models) on demand.
Unlike procedural language, here in oops programming language programs are organized around objects and data rather than action and logic.
The main OOPs Principles used in apex Language are,
In this real word Any entity that has state and behavior is known as an object. It can be physical and logical.
Example: Book, Ball, Spoon, Van, water Bottle, etc.
Class is a Collection of objects. It is a logical entity.
Example: The animal is class and Animal types are objects. There are many objects in a class.
When one object acquires all the properties and behavior of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
Example: Parents producing the children inheriting qualities of the parents.
When one task is performed by different ways simply it’s called as polymorphism. we use method overloading and method overriding to achieve polymorphism.
Example: We want to go from one place to another place in the vehicle but the vehicle type is different.
Hiding internal details and showing functionality is known as abstraction. we use abstract class and interface to achieve abstraction.
Binding (or wrapping) code and data together into a single unit is known as encapsulation.
Example: ATM machines, we don’t know the inside ATM.