Object Oriented Programming · Unit 2
Classes, Objects, and Data Members
Exam-focused notes for Classes, Objects, and Data Members (Object Oriented Programming, BIT153): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.
What this unit covers
- Class definition and declaration
- Data members and member functions
- Access specifiers: public, private, protected
- Objects as instances of classes
- Objects as function arguments
- Returning objects from functions
Returning objects from functions
How do you return object in function? Describe with an example. [5]
In C++, a function can return an object of a class just like it returns any other data type. The return type of the function is specified as the class name, and the return statement returns an object of that class. Syntax: --- - The return type of the funct...
Full solved answer →Write a program to demonstrate returning object from functions in C++. [5]
In C++, a function can return an object of a class just like it returns any other data type. The returned object is a copy of the local object created inside the function. Point Explanation -------------------- Return type The return type of add() is Rectan...
Full solved answer →More from this unit
Explain the chain of constructor and destructor between sub classes and super classes during inheritance with example.Create a class named 'Point' with data members x and y. Overload the + operator to add the value of two objects of this class.[5+5]
--- (a) Chain of Constructor and Destructor in Inheritance In C++ inheritance, when an object of a derived (sub) class is created or destroyed, constructors and destructors are called in a specific order involving both the base (super) class and the derived...
Full solved answer →Objects as function arguments
Explain use of objects as function arguments with example [5]
In C++, objects of a class can be passed as arguments to functions, just like variables of built-in data types. This allows functions to work with the data and behavior encapsulated within objects. When an object is passed to a function, the function receiv...
Full solved answer →Make Unit 2 stick
Practice BIT153 with flashcards & quizzes