Introduction to OOP Using Java — Chapter 4.
1. Computer Languages
Computer languages are broadly classified into:
• Low-Level Languages
◦ Machine-level language
◦ Assembly-level language
◦ Limitations: time-consuming, difficult error detection, machine-dependent
• High-Level Languages
◦ Machine-independent; instructions similar to simple English
◦ Classified into: Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP)
2. Procedure-Oriented Programming (POP)
Definition: A high-level programming approach in which emphasis is laid on functions rather than data values.
• Data values are loosely attached to functions and can flow freely between them
• Miscalculation of data may affect the rest of the program — data security is a real concern
Examples: BASIC, COBOL, FORTRAN, C
Characteristics:
• Emphasis on functions (logical steps)
• Functions share global data
• Data moves freely from function to function
• Uses the top-down approach
Top-Down Approach: Begin with the entire problem as one large task, then break it into smaller and smaller
functions.
3. Drawbacks of POP
• Global data means changes may require modifications across many functions
• Not suitable for solving complex real-life problems
4. Object-Oriented Programming (OOP)
Definition: A modular programming approach that allows data to be used within a stipulated program area.
Emphasis is laid on data rather than functions.
• Developed to increase programmer productivity and overcome POP limitations
• Data does not flow freely — the problem is decomposed into objects
Object: An entity created and maintained with a set of related data such that the data cannot be changed by
other functions or objects. Data is accessible only through the object's own functions.
Examples: C++, Java, Smalltalk, Eiffel, Simula 67
5. Features of OOP
• Emphasis on data rather than functions
• Ensures data security and prevents data corruption
• Objects contain their own data and functions
• Objects interact with one another through functions
6. Principles of OOP
The four main principles are: Data Abstraction, Inheritance, Polymorphism, Encapsulation.
A. Encapsulation
Data and functions are kept together in classes and are not accessible to the outside world except through
related functions.
Definition: The system of wrapping data and functions of an object together as a single unit such that data
items are accessible only within the functions of the same object.
• Data in an object = properties/attributes; Functions = methods
• Data hiding: data is isolated so it cannot be accessed directly from outside the class
B. Abstraction
Showing only the essential features while hiding unnecessary implementation details.
Definition: Representing only the essential features without including background details.
• Objects promote abstraction because data members can only be accessed through related functions
• Abstraction is an absolute property of an object
C. Inheritance
Definition: The mechanism by which a class acquires some properties from another class.
• Parent / Base / Superclass — the class whose properties are inherited
• Child / Subclass — the class that acquires those properties
• Supports hierarchical classification (e.g. Geometry → 2D Figures → Circle)
Reusability: A mechanism that allows reusing data members and methods of an existing class in a new class,
attained through inheritance.
D. Polymorphism
From Greek: poly (many) + morph (forms). Behaviour depends on the type of data used.
Definition: The process of using a function for more than one purpose; allows different internal structures while
keeping the same external interface.
Example: An addition function returns a sum for numbers, but concatenation ("Ava" + " Smith" = "Ava Smith")
for strings.
7. Dynamic Binding
Definition: The process of linking a function call with the corresponding function signature at run time (during
program execution).
• Compiler generates the machine-code address of a function and places it at the call site
• At execution: function call encountered → control transfers to the address → function runs → control
returns
8. Advantages of OOP
• Existing classes can be extended through inheritance
• Data hiding enables development of secure programs
• Multiple instances of an object can coexist without interference
• Different modules can be created within a project using objects
• Highly beneficial for solving complex problems
• Makes software easier to modify and maintain
Quick Reference: POP vs OOP
POP OOP
Emphasis on functions Emphasis on data
Data moves freely Data access is controlled
Top-down approach Bottom-up approach
Less secure More secure
Smaller programs Complex real-world problems
C, COBOL, FORTRAN Java, C++, Smalltalk
Doubt Clarifications
1. What is a 'corresponding class'?
A class is a blueprint from which objects are created. The data and functions belonging to, say, the Student
class stay together inside that class. 'Corresponding class' simply means the class to which that data and those
functions belong.
2. What is the 'calling program'?
The part of the program that requests a function to run. E.g. [Link]() — the code that wrote that line is
the calling program.
3. 'Interface between data items and the calling program'
Think of a bank account: you cannot directly edit the database. You use Deposit / Withdraw / Check Balance.
Those functions are the interface — they provide controlled access to hidden data. Same idea in OOP.
4. TV Remote Analogy (Encapsulation)
• TV = Object
• Internal circuitry/settings = Data
• Remote buttons = Methods
You cannot reach inside the TV and alter its circuitry directly. You must use the remote buttons. Likewise,
outside code cannot access the data directly — it must use the object's methods.
5. String Concatenation (Polymorphism)
"Oxford" + "University" → "OxfordUniversity". Same + operator: numbers → addition, strings → joining. Classic
polymorphism.