Java OOP Concepts - Beginner Friendly Notes
1. What is OOP?
OOP (Object Oriented Programming) is a programming concept where we use objects and classes
to design programs. It helps in code reusability, scalability, and maintainability.
2. Class and Object
Class is a blueprint, Object is an instance of class.
class Car {
String color;
void drive() {
[Link]("Car is driving");
}
}
public class Main {
public static void main(String[] args) {
Car c = new Car();
[Link] = "Red";
[Link]();
}
}
3. Encapsulation
Encapsulation means wrapping data and methods into a single unit and restricting direct access
using private variables.
class Student {
private int age;
public void setAge(int age) {
[Link] = age;
}
public int getAge() {
return age;
}
}
4. Inheritance
Inheritance allows one class to use properties of another class.
class Animal {
void sound() {
[Link]("Animal makes sound");
}
}
class Dog extends Animal {
void bark() {
[Link]("Dog barks");
}
}
5. Polymorphism
Polymorphism means same method behaves differently.
class Math {
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}
6. Abstraction
Abstraction means hiding implementation and showing only functionality.
abstract class Vehicle {
abstract void start();
}
class Bike extends Vehicle {
void start() {
[Link]("Bike starts with kick");
}
}
7. Interface
Interface is used for full abstraction.
interface Animal {
void sound();
}
class Cat implements Animal {
public void sound() {
[Link]("Meow");
}
}