1. Learning Objectives
After studying this chapter, you should be able to:
- Explain the meaning of a computer program and programming paradigm.
- Understand the basic difference between procedural and object-oriented programming.
- Define object-oriented programming (OOP).
- Explain abstraction, encapsulation, inheritance and polymorphism at an introductory level.
- Recognise real-life examples of object-oriented concepts.
2. What Is Programming?
A computer program is a set of instructions written to make a computer perform a particular task.
Programming is the process of designing, writing, testing and maintaining those instructions using a programming language.
Example
A program can calculate the total marks of a student, display a result, manage a library or process a bank transaction.
A programming paradigm is an approach or style used to design and organise a program.
3. Programming Approaches
3.1 Procedural Programming
In procedural programming, a program is organised around procedures or functions that perform specific tasks. The instructions generally describe the steps needed to solve a problem.
Examples of procedural programming languages include C and BASIC, although many languages support more than one programming style.
3.2 Object-Oriented Programming
Object-oriented programming organises a program around objects that combine data with operations that work on that data.
Java is primarily an object-oriented programming language. Its programs commonly use classes and objects to represent entities and their behaviour.
4. What Is Object-Oriented Programming?
Object-Oriented Programming (OOP) is a programming approach in which software is designed using objects containing data and the operations associated with that data.
For example, a student object could contain a student's name, roll number and marks. Operations associated with the student could calculate total marks or display a result.
Why use OOP?
- Organisation: Related data and operations can be grouped together.
- Reusability: Classes and methods can be reused in suitable situations.
- Maintainability: A well-designed program can be easier to update and test.
- Modularity: A large program can be divided into smaller, understandable components.
5. Main OOP Concepts
5.1 Abstraction
Abstraction means focusing on essential features while hiding unnecessary implementation details.
5.2 Encapsulation
Encapsulation means combining data and the methods that operate on that data within a single unit, such as a class. In Java, access control can help protect an object's internal state.
5.3 Inheritance
Inheritance allows a new class to derive properties and behaviour from an existing class. It can help reuse and extend code.
5.4 Polymorphism
Polymorphism means “many forms”. In OOP, the same operation or interface can have different behaviour in different contexts.
5.5 Classes and Objects — A Preview
A class defines the structure and behaviour of a category of objects. An object is an instance of a class.
Classes and objects are introduced here to help explain OOP. Their detailed treatment belongs to the next part of your chapter sequence.
6. Procedural Programming vs OOP
| Basis | Procedural Approach | Object-Oriented Approach |
|---|---|---|
| Main organisation | Procedures or functions | Classes and objects |
| Main focus | Steps and operations | Objects, their data and behaviour |
| Data organisation | Data is handled by procedures; organisation varies by language and design | Data and related methods can be grouped in classes |
| Code reuse | Can reuse functions and modules | Can reuse classes, methods and inheritance where appropriate |
| Examples | C, traditional BASIC | Java, C++ |
Important: This table presents the basic classroom distinction. The features of a particular language depend on its design, and some languages support both approaches.
7. Everyday Examples of OOP
Example 1: School Management
- Data: student name, roll number and marks.
- Behaviour: calculate total, calculate average and display result.
- Possible object: one particular student.
Example 2: Bank Account
- Data: account number and balance.
- Behaviour: deposit, withdraw and display balance.
- Encapsulation helps control access to the balance.
Example 3: Shape
- Different shapes can have different area calculations.
- A common operation such as
calculateArea()can behave differently for different shapes. - This illustrates the basic idea of polymorphism.
Example 4: Vehicle
- A general Vehicle class could contain common features.
- Car and Bike classes could extend the general class.
- This illustrates the idea of inheritance.
8. Quick Revision
| Term | Meaning |
|---|---|
| Programming | Designing and writing instructions to solve a problem. |
| Programming paradigm | An approach to organising and designing programs. |
| OOP | A programming approach organised around objects. |
| Abstraction | Focusing on essential features and hiding unnecessary details. |
| Encapsulation | Combining data and related methods in a unit. |
| Inheritance | Deriving a class from another class. |
| Polymorphism | Allowing an operation or interface to have different forms of behaviour. |
| Class | A definition used to create objects. |
| Object | An instance of a class. |
9. Practice Exercises
A. Short-answer questions
- What is a computer program?
- Define a programming paradigm.
- What is object-oriented programming?
- Explain abstraction with one everyday example.
- What is encapsulation?
- Explain inheritance with an example.
- What is polymorphism?
- State two possible advantages of OOP.
B. Application questions
- Identify possible data and behaviour for a Library Book object.
- How can a Car class reuse common features of a Vehicle class?
- Give an example where the same operation has different behaviour for different objects.
- Explain the difference between a class and an object using a student example.
Show suggested answers
- A computer program is a set of instructions that makes a computer perform a task.
- A programming paradigm is an approach to designing and organising programs.
- OOP is a programming approach organised around objects that combine data and related operations.
- Abstraction focuses on essential features while hiding unnecessary details; an ATM is one example.
- Encapsulation groups data and related methods into a unit such as a class.
- Inheritance allows a new class to derive features and behaviour from an existing class.
- Polymorphism allows the same operation or interface to behave differently in different contexts.
- Possible advantages include code organisation, reuse, modularity and easier maintenance.
- Possible data: book title, author and ISBN. Possible behaviour: issue, return and display details.
- A Car class can extend a Vehicle class and add car-specific features.
- A sound operation may make a Dog object bark and a Cat object meow.
- A Student class is a definition; a particular student with a name and roll number is an object.
These are suggested answers. Other correct explanations and examples are acceptable.
10. Interactive MCQ Quiz
Answer all 10 questions, then click Submit Quiz to see your score and feedback.
Well Done!
You have completed the introductory notes on Object Oriented Programming Concepts.
Next, continue with Part II: Elementary Concept of Objects and Classes.