Java Class Notes – Object-Oriented Programming Basics
Description:
This file contains an easy-to-follow introduction to OOP concepts in Java: classes, objects,
encapsulation, inheritance, and abstraction. It is designed for high school or first-year CS
students.
🧱 What is Object-Oriented Programming (OOP)?
Object-Oriented Programming (OOP) is a method of programming that organizes code using
objects and classes. Java is a fully object-oriented language (except for primitive types).
🧩 Main Principles of OOP
1. Class
A blueprint or template for creating objects.
2. Object
An instance of a class.
3. Encapsulation
Hiding the internal details of objects and exposing only what's necessary.
4. Inheritance
A mechanism where one class can inherit features (fields and methods) from another.
5. Abstraction
Showing only essential features and hiding the unnecessary details.
🏗️Example: Defining a Simple Class
java
CopyEdit
class Student {
int id;
String name;
void display() {
System.out.println("ID: " + id);
System.out.println("Name: " + name);
}
}
🧪 Creating an Object of a Class
java
CopyEdit
public class Main {
public static void main(String[] args) {
Student s1 = new Student();
s1.id = 101;
s1.name = "Alice";
s1.display();
}
}
🧠 Mini Exercise
Create a class Car with:
Properties: brand, model, year
Method: start() prints "Car is starting..."
✅ Quick Review
Term Description
Class Blueprint of objects
Object Instance of a class
Method Function inside a class
Constructor Special method to initialize objects