Object Oriented Programming

Grade 10 · Technology · Study Guide

A comprehensive overview of OOP principles including encapsulation, inheritance, polymorphism, and abstraction.

Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around data, or objects, rather than functions and logic. An object is a data field with unique attributes and behavior. OOP focuses on the objects that programmers want to manipulate rather than the logic required to manipulate them.

The four core pillars of OOP are encapsulation, inheritance, polymorphism, and abstraction. Encapsulation bundles data (attributes) and methods (functions) that operate on the data into a single unit called a class, and restricts direct access to some components. Inheritance allows a class (child/subclass) to acquire the properties and behaviors of another class (parent/superclass), promoting code reuse.

Polymorphism enables objects of different classes to be treated as objects of a common superclass. It allows one interface to be used for a general class of actions — the specific action is determined by the exact nature of the situation. Abstraction hides complex implementation details and exposes only the necessary features of an object.

Classes serve as blueprints for creating objects. When an object is created from a class, it is called instantiation. Each object has its own set of instance variables but shares the methods defined in its class. Understanding these concepts is foundational for writing scalable, maintainable, and reusable code in languages like Java, Python, and C++.

Key terms

Class
A blueprint or template that defines the attributes and methods common to all objects of a certain kind.
Object
An instance of a class that contains real values for the attributes defined in the class.
Encapsulation
The bundling of data and methods into a single unit (class) while restricting direct access to internal components.
Inheritance
A mechanism where a subclass derives attributes and behaviors from a parent class, enabling code reuse.
Polymorphism
The ability for different classes to be treated as instances of the same class through a shared interface, allowing methods to behave differently based on the object.
Abstraction
The process of hiding complex implementation details and showing only the essential features of an object or system.

Flashcards

Constructor
A special method called when an object is instantiated; used to initialize the object's attributes.
Method
A function defined inside a class that describes the behaviors of an object.
Instance variable
A variable defined in a class for which each instantiated object has a separate copy.
Subclass
A class that inherits from another class (the superclass), gaining its attributes and methods.
Overriding
When a subclass provides a specific implementation of a method already defined in its superclass.
Access modifier
Keywords (public, private, protected) that set the accessibility of classes, methods, and variables.
Interface
An abstract type that defines a contract of methods that implementing classes must provide.
Abstract class
A class that cannot be instantiated on its own and may contain abstract methods that subclasses must implement.

Questions

  1. Which OOP principle allows a child class to inherit properties and methods from a parent class?

    1. Encapsulation
    2. Polymorphism
    3. Inheritance
    4. Abstraction
    Show answer

    Answer: Inheritance

    Inheritance is the OOP principle that allows a child class to acquire properties and methods from a parent class, enabling code reuse.

  2. Encapsulation in OOP means that an object's internal data can always be accessed directly from outside the class.

    Show answer

    Answer: False

    Encapsulation restricts direct access to internal data; access is typically controlled through getter and setter methods.

  3. The process of creating an object from a class is called ________.

    Show answer

    Answer: instantiation

    Instantiation is the process of creating a specific object (instance) from a class blueprint.

  4. What does polymorphism allow in OOP?

    1. A class to hide its internal data from other classes
    2. A subclass to inherit all methods from a superclass
    3. Different objects to be treated as instances of a common superclass with behavior varying by type
    4. A programmer to write code without using classes
    Show answer

    Answer: Different objects to be treated as instances of a common superclass with behavior varying by type

    Polymorphism allows objects of different classes to be treated as instances of a shared superclass, with method behavior varying depending on the actual object type.

  5. Abstraction focuses on exposing the complex internal details of a class to the user.

    Show answer

    Answer: False

    Abstraction hides complex internal details, exposing only necessary functionality to the user.

Get a personalized course on Object Oriented Programming built around your child.