Java Object-Oriented Programming (OOP) - Lesson
Plan
1. Start with a Real-World Example
Ask: What is a Student?
Students answer: Roll Number, Name, Department, Age.
Explain that a Student class is a blueprint, while actual students are objects created from it.
2. Class
Definition: A class is a blueprint used to create objects.
class Student {
int rollNo;
String name;
}
3. Object
Student s1 = new Student();
Student s2 = new Student();
[Link] = 101;
[Link] = "Rahul";
[Link] = 102;
[Link] = "Priya";
Each object stores its own data independently.
4. Constructor
A constructor initializes an object automatically when it is created.
class Student {
int rollNo;
String name;
Student(int r, String n){
rollNo = r;
name = n;
}
}
Object creation:
Student s1 = new Student(101, "Rahul");
Student s2 = new Student(102, "Priya");
5. Method
Methods define the behavior of an object.
void display(){
[Link](rollNo);
[Link](name);
}
[Link]();
6. Complete Program
class Student {
int rollNo;
String name;
Student(int rollNo, String name){
[Link] = rollNo;
[Link] = name;
}
void display(){
[Link]("Roll No : " + rollNo);
[Link]("Name : " + name);
}
}
public class Main {
public static void main(String[] args){
Student s1 = new Student(101,"Rahul");
Student s2 = new Student(102,"Priya");
[Link]();
[Link]();
}
}
7. Four Pillars of OOP
Encapsulation: Keep data and methods together.
Inheritance: Reuse existing classes.
Polymorphism: Same method name, different behavior.
Abstraction: Show essential details and hide implementation.
Suggested 1.5-Hour Lesson Plan
10 min - Why OOP? Real-world examples
15 min - Class
20 min - Objects
20 min - Constructor
15 min - Methods
10 min - Complete Student program
10 min - Four pillars and Q&A;
Practice Questions
1. Create a Car class with brand and price.
2. Create two Car objects and print their details.
3. Create an Employee class using a constructor.
4. Create a Book class with a display() method.
5. Create three Student objects and print their information.