3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Design Java classes.
- Create and use objects.
- Apply inheritance and method overriding.
- Create constructors in Java.
- Design Java applications using OOP principles.
3.2 Overview
Object-Oriented Programming (OOP) is a programming approach that organizes software using objects and classes. Java is a fully object-oriented programming language that uses OOP principles to create reusable and scalable applications.
OOP concepts are important in:
- enterprise software,
- banking systems,
- web applications,
- mobile applications,
- and real-world software development.
This lesson introduces learners to practical implementation of OOP concepts using Java programming.
Understanding OOP is important because modern software systems are built using object-oriented design principles.
PA0101 — Design a Class
A class acts as a blueprint for creating objects.
Java Example:
public class Student {
String name;
int age;
}
Practical Activity
Learners must:
- create Java classes,
- declare attributes,
- and apply Java class syntax.
PA0102 — Apply Inheritance and Overriding with toString() Method
Inheritance allows one class to inherit properties from another class.
Java Example:
class Vehicle {
String brand = “Generic Vehicle”;
public String toString() {
return “Brand: “ + brand;
}
}
class Car extends Vehicle {
int year = 2024;
@Override
public String toString() {
return super.toString() + “, Year: “ + year;
}
}
Practical Activity
Learners must:
- create parent and child classes,
- apply inheritance,
- override methods,
- and display object information.
PA0103 — Create a Java Class and a Couple of Objects
Objects are instances of classes.
Java Example:
public class Main {
public static void main(String[] args) {
Student s1 = new Student();
s1.name = “Alice”;
s1.age = 20;
Student s2 = new Student();
s2.name = “Bob”;
s2.age = 22;
System.out.println(s1.name + “ is “ + s1.age);
System.out.println(s2.name + “ is “ + s2.age);
}
}
Practical Activity
Learners must:
- create objects,
- assign object values,
- and display object information.
PA0104 — Book Class and Three Instances
Classes can create multiple object instances.
Java Example:
public class Book {
String title;
String author;
int year;
public Book(String t, String a, int y) {
title = t;
author = a;
year = y;
}
public String toString() {
return title + “ by “ + author + “ (” + year + “)”;
}
}
Practical Activity
Learners must:
- create Book classes,
- instantiate multiple objects,
- and display book information.
PA0105 — Introduce State of an Object with Speed Variable
Objects maintain state using variables.
Java Example:
class Car {
int speed = 0;
void accelerate(int value) {
speed += value;
}
void brake(int value) {
speed -= value;
}
}
Practical Activity
Learners must:
- create object states,
- modify variable values,
- and demonstrate object behaviour.
PA0106 — Create a Constructor Program in Java
Constructors initialize object values during object creation.
Java Example:
public class Student {
String name;
int age;
public Student(String n, int a) {
name = n;
age = a;
}
public String toString() {
return name + “ is “ + age + “ years old.”;
}
}
Practical Activity
Learners must:
- create constructors,
- initialize objects,
- compile Java programs,
- and execute applications.
PA0107 — Design a Rectangle Class
Classes can contain methods that perform calculations.
Java Example:
public class Rectangle {
int length;
int width;
public Rectangle(int l, int w) {
length = l;
width = w;
}
public int area() {
return length * width;
}
public int perimeter() {
return 2 * (length + width);
}
public String toString() {
return “Rectangle [Length=” + length + “, Width=” + width + “]”;
}
}
Practical Activity
Learners must:
- create rectangle classes,
- calculate area and perimeter,
- and display object information.
AK0101 — OOP Functionalities
OOP Functionality — Description
Encapsulation — Hides data inside classes
Inheritance — Allows child classes to inherit properties
Polymorphism — Same method with different behaviours
Abstraction — Hides unnecessary implementation details
Practical Activity
Learners must:
- identify OOP principles,
- apply object-oriented concepts,
- and explain software design benefits.
IAC0101 — Expected Results with File Systems and Directories in Java are Achieved
Java programs must follow correct file management rules.
Java File Management Rules
- Save files with .java extension
- File name must match public class name
- Compile using javac
- Execute using java command
- Organize files into directories and packages
Java Example:
javac Book.java
java Book
Practical Activity
Learners must:
- save Java files correctly,
- compile programs,
- execute applications,
- and organize Java project directories.
3.5 Key Notes / Summary
- OOP organizes software using classes and objects.
- Classes act as blueprints for objects.
- Inheritance supports code reuse.
- Constructors initialize objects.
- Object state is maintained using variables.
- Java programs must follow correct file management rules.
- OOP improves software scalability and maintainability.