Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around objects, which represent real-world entities or concepts. It focuses on using classes and objects to model and manipulate data and behavior.
Below is an explanation of the key terminology and features that define Object-Oriented Programming:
Class:
Car class might have data members like color, model, speed, and methods like accelerate() and brake().Object:
myCar could be an object of the Car class with specific attributes like color = red and model = sedan.Encapsulation:
private, protected, and public.private, and public methods (getters and setters) can be used to access or modify them safely.Abstraction:
Shape class can provide an abstract draw() method, but each specific shape (like Circle, Rectangle) will implement it differently.Inheritance:
Dog class can inherit from an Animal class, inheriting general properties like name, age, and eat() while also having its own specific methods like bark().Polymorphism:
draw() method may behave differently depending on whether it’s called on a Circle or a Rectangle object.Constructor:
Person class, a constructor might initialize a name and age when an object is created.Destructor:
Access Modifiers:
private data members, but public methods to manipulate them safely.Overloading:
+, -, *, etc., to be used with user-defined classes in a meaningful way.add() could be overloaded to accept integers, doubles, or even strings as arguments.Encapsulation:
class Person {
private:
string name;
int age;
public:
void setName(string n) { name = n; }
string getName() { return name; }
};
Abstraction:
class Shape {
public:
virtual void draw() = 0; // Pure virtual function
};
class Circle : public Shape {
public:
void draw() { cout << "Drawing a circle!" << endl; }
};
Inheritance:
class Animal {
public:
void speak() { cout << "Animal makes a sound" << endl; }
};
class Dog : public Animal {
public:
void speak() { cout << "Dog barks!" << endl; }
};
Polymorphism:
class Animal {
public:
virtual void sound() { cout << "Some animal sound" << endl; }
};
class Dog : public Animal {
public:
void sound() { cout << "Bark!" << endl; }
};
Code Reusability:
Dynamic Binding:
class Shape {
public:
virtual void draw() { cout << "Drawing shape!" << endl; }
};
class Circle : public Shape {
public:
void draw() { cout << "Drawing a circle!" << endl; }
};
Object-Oriented Programming (OOP) provides powerful concepts such as encapsulation, abstraction, inheritance, polymorphism, and code reuse, which help in creating flexible, maintainable, and scalable software. The terminology and features of OOP are essential for understanding how OOP principles work together to solve real-world programming challenges. Languages like C++, Java, and Python leverage these features to provide developers with tools to build robust and modular applications.
Open this section to load past papers