3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Create Java classes.
- Declare fields and methods.
- Create constructors.
- Instantiate objects.
- Apply object-oriented programming concepts.
3.2 Overview
Classes are the foundation of object-oriented programming in Java. A class acts as a blueprint used to create objects. Classes contain fields, constructors, and methods that define the state and behaviour of objects.
This lesson introduces learners to the practical creation and use of Java classes and objects.
Java classes are important in:
- object-oriented programming,
- enterprise software development,
- data modelling,
- and application design.
Understanding classes is important because almost every Java application is built using classes and objects.
PA0901 — Create a Java Class
A class defines the structure and behaviour of objects.
Java Example:
public class Student {
}
Practical Activity
Learners must:
- create a Java class,
- apply Java naming conventions,
- and save the class correctly.
PA0902 — Declare Fields
Fields store object data inside a class.
Java Example:
public class Student {
String name;
int age;
}
Field — Purpose
name — Stores learner name
age — Stores learner age
Practical Activity
Learners must:
- declare fields,
- assign correct data types,
- and create meaningful variable names.
PA0903 — Create Constructors
Constructors initialize objects when they are created.
Java Example:
public class Student {
String name;
int age;
Student(String name, int age) {
this.name = name;
this.age = age;
}
}
Practical Activity
Learners must:
- create constructors,
- initialize object values,
- and apply constructor syntax correctly.
PA0904 — Create Methods
Methods define object behaviour.
Java Example:
public class Student {
String name;
int age;
void displayInfo() {
System.out.println(name);
System.out.println(age);
}
}
Practical Activity
Learners must:
- create methods,
- display object information,
- and call methods successfully.
PA0905 — Instantiate Objects
Objects are created from classes using the new keyword.
Java Example:
Student student1 = new Student(“Alice”, 20);
Practical Activity
Learners must:
- create objects,
- initialize object values,
- and display object data.
PA0906 — Access Object Fields and Methods
Object fields and methods are accessed using the dot operator.
Java Example:
student1.displayInfo();
Practical Activity
Learners must:
- access object methods,
- display object values,
- and use object references correctly.
PA0907 — Create Multiple Objects
Classes can create many objects with different values.
Java Example:
Student student1 = new Student(“Alice”, 20);
Student student2 = new Student(“John”, 22);
Practical Activity
Learners must:
- create multiple objects,
- assign different values,
- and display all object information.
PA0908 — Create Complete Java Class Program
Java classes are combined into complete object-oriented applications.
Java Example:
public class Student {
String name;
int age;
Student(String name, int age) {
this.name = name;
this.age = age;
}
void displayInfo() {
System.out.println(“Name: “ + name);
System.out.println(“Age: “ + age);
}
public static void main(String[] args) {
Student student1 = new Student(“Alice”, 20);
student1.displayInfo();
}
}
Importance of Java Classes
Java classes support:
- object-oriented programming,
- reusable code,
- modular application design,
- and software scalability.
3.5 Key Notes / Summary
- Classes are blueprints for objects.
- Fields store object data.
- Constructors initialize objects.
- Methods define behaviour.
- Objects are created using the new keyword.
- Java classes support object-oriented programming.