Introduction
OOPS stands for object-oriented programming. All modern programming languages are based on the OOPS concept. Older programming languages like PASCAL, FORTRAN, C, etc., are not obsessed with objects. They are somewhat procedural programming languages.
What is OOPs concepts in Java?
Objects Oriented Programming is a programming style based on the idea of objects and classes to represent the Data. JAVA is based on object-oriented programming.
Class is not a real-world entity but a template or prototype. In Computer memory, Class doesn't occupy memory, but it imparts an idea about the features of objects. Objects, on the other hand, are the instances of the Class. An object is an actual entity that occupies space in the memory.
Access Modifier:
The access modifier of a method defines its visibility to other classes and determines the level of access control. Common access modifiers include public, private, protected, and package-private (no explicit modifier). Public means the method can be accessed by any other class. Private restricts access to the class it belongs to. Protected allows access within its own package and by subclasses. Package-private (default, no modifier) restricts access to classes within the same package.
The Return Type:
This specifies the data type of the value that the method will return after its execution. If the method does not return any value, the return type is specified as void. Otherwise, it could be any data type like int, String, boolean, or any object type.
Method Name:
The method name is the identifier that is used to refer to it. It should follow the naming conventions of the language and typically begins with a lowercase letter. The name is usually a verb or verb phrase that clearly indicates the operation the method performs, such as calculateTotal, printDetails, or isEmpty.
Parameter List:
This is a sequence of variables enclosed in parentheses that are passed to the method. These are the inputs that the method uses to perform its operation. Each parameter is specified with a data type followed by an identifier name, and multiple parameters are separated by commas.
Exception List:
Some languages, like Java, allow methods to specify a list of exceptions that they might throw during the execution. This exception list alerts the callers of the method to provide necessary exception handling code. It's part of the method signature and is declared with the throws keyword followed by the exception types.
Method Body:
Enclosed in braces {}, the method body contains the code that defines what the method does. It consists of a series of statements that are executed when the method is called. This is where the actual logic of the method is implemented, and it's where variables are manipulated, other methods are called, loops are executed, and the return value is produced if applicable.
OOPS moves around its four most important pillars. These are; Inheritance, Polymorphism, Abstraction, and Encapsulation.
Let's discuss all these in brief.
Recommended topic Iteration Statements in Java.