Object-Oriented Programming (OOPs) is a programming paradigm based on the concept of "objects", which can contain data and code. Java is an OOPs language. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
4 Major Pillars of OOPs
There are four main pillars of object-oriented programming in Java:
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Example of a Class and Object
A class is a blueprint from which individual objects are created.
// Simple Java class example
public class Student {
int id;
String name;
public static void main(String args[]) {
// Creating an object
Student s1 = new Student();
s1.id = 101;
s1.name = "Chandu";
System.out.println(s1.id + " " + s1.name);
}
}
Leave a Reply