थोडक्यात सारांश
Object-Oriented Programming (OOP) is a way of writing programs around objects, which combine data and the functions that work on that data. It models real-world things. This topic covers the difference between procedural and object-oriented programming, and the main OOP concepts: class, object, encapsulation, abstraction, inheritance, polymorphism, dynamic binding and message passing, plus the benefits of OOP and an introduction to C++.
महत्त्वाचे मुद्दे
- Procedure-oriented programming (POP) like C focuses on functions; data moves freely between functions and is less secure. It follows a top-down approach.
- OOP like C++, Java and Python focuses on data (objects); data is hidden and accessed only through member functions. It follows a bottom-up approach.
- Class: a user-defined blueprint that describes data members and member functions. Example: class Student.
- Object: an instance of a class; a real entity in memory. Example: Student s1;
- Encapsulation: wrapping data and functions into a single unit (class). It supports data hiding using private access.
- Abstraction: showing only essential features and hiding background details (we drive a car without knowing the engine design).
- Inheritance: a new class (derived) gets properties of an existing class (base). It gives reusability.
- Polymorphism ("many forms"): the same name behaves differently in different situations. Compile-time (function and operator overloading) and run-time (virtual functions).
- Dynamic binding: the code to run for a function call is decided at run time.
- Message passing: objects communicate by calling each other's functions.
- Benefits: reusability, data security, easier maintenance, modelling of real-world problems, scalability.
- C++ was developed by Bjarne Stroustrup at Bell Labs in the early 1980s, first called "C with Classes".
- C++ I/O uses cout with the insertion operator and cin with the extraction operator, from the iostream header.
महत्त्वाच्या संज्ञा
- Object (वस्तू) – instance of a class with its own state and behaviour.
- Data hiding – preventing direct access to data from outside the class.
- Reusability – using existing code again through inheritance.
- Overloading – same function name or operator with different meanings by argument type.
- Access specifiers – private, protected, public; control visibility of members.
सूत्रे
| Point | POP (C) | OOP (C++) |
|---|---|---|
| Focus | functions | objects (data) |
| Approach | top-down | bottom-up |
| Data security | less (global data) | more (data hiding) |
| Reusability | limited | inheritance |
| Overloading | not supported | supported |
| Example | C, Pascal | C++, Java |
A first C++ program:
५ महत्त्वाचे प्रश्न
Q1. Differentiate between a class and an object.
A class is a blueprint or template that defines data and functions; it uses no memory for data until objects are made. An object is an instance of a class that occupies memory. Example: Car is a class; myCar is an object.
Q2. What is encapsulation? How does it give data hiding?
Encapsulation binds data and functions into a class. By declaring data members private, they can be reached only through public member functions, so outside code cannot change them directly. This is data hiding.
Q3. Explain the basic concepts of OOP.
- Class and object.
- Encapsulation and data hiding.
- Abstraction.
- Inheritance (reusability).
- Polymorphism (overloading, virtual functions).
- Dynamic binding and message passing.
- Give a one-line example for each (e.g. BankAccount class with deposit()).
Q4. Compare procedure-oriented and object-oriented programming.
- POP divides the program into functions; OOP into objects.
- POP uses top-down design; OOP bottom-up.
- In POP data is mostly global; OOP hides data inside classes.
- OOP supports inheritance, polymorphism and overloading; POP does not.
- Examples: C (POP); C++, Java (OOP).
Q5. What are the benefits and applications of OOP?
- Benefits: code reuse, data security, easy upgrades, modular design, fewer errors in big projects.
- Real-world modelling makes design natural.
- Applications: GUI applications, games, simulation, CAD/CAM, real-time systems, object databases.
- Many modern languages (C++, Java, Python, C#) are object-oriented.
परीक्षेसाठी टीप
The POP vs OOP table and "explain OOP concepts" are near-certain questions. Give a small real-life example for each concept to score full marks.