Object-Oriented Programming (OOP) with Java - Notes
1. Basic Concepts of OOP
| Concept | Description |
|----------------|---------------------------------------------------------------|
| Class | Blueprint for objects. It defines properties and behaviors. |
| Object | Instance of a class. Represents a real-world entity. |
| Encapsulation | Wrapping data and methods into a single unit (class). |
| Abstraction | Hiding internal details, showing only essential features. |
| Inheritance | One class inherits properties and behaviors from another. |
| Polymorphism | Ability to take many forms - method overloading/overriding. |
2. Class and Object Example
class Student {
String name;
int age;
void display() {
System.out.println(name + " is " + age + " years old.");
public class Main {
public static void main(String[] args) {
Student s1 = new Student();
s1.name = "John";
s1.age = 20;
s1.display();
3. Encapsulation
Using private variables and public getters/setters.
class Employee {
private int salary;
public void setSalary(int s) {
salary = s;
public int getSalary() {
return salary;