Computer Science 2B
Formal Academic Notes
Topic: Java Object-Oriented Programming (OOP) Concepts
Year: 2025
These notes provide a formal overview of the principles of Object-Oriented Programming
(OOP) in Java. They aim to enhance theoretical understanding and practical application
through structured explanations, examples, and reflective revision questions suitable for
university-level study.
1. Introduction to Object-Oriented Programming
OOP is a programming paradigm based on the concept of 'objects',
which can contain data (fields) and methods (functions). Java, as an OOP language,
promotes modular, reusable,
and maintainable code.
2. Classes and Objects
A class is a blueprint or template that defines the structure and behavior of objects.
An object is an instance of a class, representing a real-world entity.
Example:
class Student {
String name;
int age;
void display() {
System.out.println(name + " is " + age + " years old.");
}
}
3. Encapsulation
Encapsulation refers to bundling data and methods that operate on that data within one
unit.
It helps protect object integrity by restricting direct access to certain components using
access modifiers such as private and public.
4. Inheritance
Inheritance allows one class to inherit fields and methods from another class, promoting
code reusability.
Example:
class Animal {
void eat() { System.out.println("Eating..."); }
}
class Dog extends Animal {
void bark() { System.out.println("Barking..."); }
}
5. Polymorphism
Polymorphism enables a single interface to represent different underlying forms (data
types).
It allows methods to perform different functions based on the object that calls them.
Example: Method overriding and method overloading.
6. Abstraction
Abstraction hides the complex implementation details and shows only essential features of
the object.
It can be achieved using abstract classes and interfaces.
7. Constructors and the 'this' Keyword
Constructors are special methods used to initialize objects.
The 'this' keyword refers to the current instance of the class.
8. Access Modifiers
Java provides access modifiers such as public, private, protected, and default to control
the visibility of classes, variables, and methods.
9. Composition vs. Inheritance
Composition represents a 'has-a' relationship while inheritance represents an 'is-a'
relationship.
Composition is preferred for flexibility and reduced coupling.
10. Importance of OOP in Software Design
OOP enhances modularity, maintainability, and scalability in software development.
It forms the foundation for modern Java frameworks and enterprise applications.
Short Revision Questions
1 Define Object-Oriented Programming and explain its four main principles.
2 Differentiate between a class and an object in Java.
3 Explain how encapsulation enhances code security.
4 Provide a Java example that demonstrates inheritance.
5 Discuss the significance of polymorphism in object-oriented systems.