oops, concepts in java provide suggestions to develop objects in programming languages.
oops, programming language introduced for representing a real-world business object by achieving security.
Another reason to invent oops is to achieve dynamic method dispatching.
which means from user program we should call an operational method only once and it should
execute from different implementation classes automatically based on the class object we loaded.
Definition of OOPS
OOPS is a specification or methodology or technique that provide a way of modularizing a program by providing partition memory area for both data and logic that can be used as a template from creating such modules(object) on demand.
Specification means a document that contains rule and regulation for developing a new application.
OOPS, the specification provides a guideline for developing a new language for automating business by creating its object using a program.
Java supports the following oops concepts in java −
- Class — A class is a logical construct of the object that defines/represents object, logically with that object’s properties and Behaviors it is one of the important oops concepts in java.
A class can contain any of the following variable types.
Local variables −
Variables defined inside methods, constructors or blocks are called local variables.
The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed. Here test variable inside forwarding method is a local variable.
Instance variables −
Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated.
Instance variables can be accessed from inside any method, constructor or blocks of that particular class. Here Gear, Color are instance variable.
Class variables −
Class variables are variables declared within a class, outside any method, with the static keyword. Here Company is the Class variable.
- Object — It is encapsulated form of a static and non-static method and variable.
- Inheritance — In oops Inheritance is the process of accessing the properties of the parent class in our subclass is known as Inheritance. The process of creating a class to reuse existed class members using our class name or object is called inheritance.
- Polymorphism — More than one method with the same name but different signature defined in the same class or with the same signature defined in the different class is called as polymorphism.Following oops concept demonstrate different types of polymorphism.
- Method Overloading
- Method Overriding
More than one method with the same name and with the same signature defined in the same class is called as Method Overloading.
Method Overriding in oops-
More than one method with same name and same signature but defined in the different class is called as Method Overriding.
- Encapsulation in oops– Encapsulation is the process of hiding the implementation details from the outside world and accessing through a publicly exposed method that means setter or getter method.
- Abstraction in java — Abstraction is the process of hiding implementation details and providing functionality to the user, in other words, we can say show functionality and hide complexity. Abstraction can be implemented using abstract class and interface.