Blog
Object Oriented Programming BSCS 2nd Term 2019 Past Paper UOS
University of Sargodha (UOS) Object Oriented Programming past paper 2019 for BS 2nd term – short questions with clear, solved answers and C++ examples.
OOP Past Paper 2019 – short questions (text version)
University of Sargodha – Object Oriented Programming, Examination 2019 (BS 2nd term)
Only the short (objective) questions were available in the copy we received. The long questions will be added when we get the original paper.
- What is the main difference between a class and an object?
- What is constructor overloading?
- Differentiate between single and multiple inheritance.
- What is the difference between compile-time binding and run-time binding?
- Explain static data of a class.
- What is a template class? Define its syntax.
- Define operator overloading.
- Why are destructors not overloaded?
- Explain the concept of the this pointer.
- Which OOP concept is used as a reuse mechanism?
- What are the operators that cannot be overloaded?
- If class A is a friend of class B, which member functions of class A can access the private members of class B?
Solved short questions – OOP 2019
- A class is a logical blueprint (data members + member functions) and takes no memory for data when declared; an object is a physical instance of the class that occupies memory and has its own values, e.g.
Car c1; - Constructor overloading: defining more than one constructor in a class with different parameter lists, so objects can be initialized in different ways – e.g.
Box(),Box(int side),Box(int l, int w, int h). - Single inheritance: a derived class has one base class (
class B : public A). Multiple inheritance: a derived class has two or more base classes (class C : public A, public B), which can cause ambiguity such as the diamond problem. - Compile-time (static/early) binding: the function call is linked to its definition by the compiler – function overloading, operator overloading, non-virtual calls. Run-time (dynamic/late) binding: the call is resolved while the program runs according to the actual object type – virtual functions called through base pointers or references.
- A static data member is declared with
static; only one copy exists, shared by all objects of the class. It must be defined outside the class (int Student::count = 0;) and is often used for counters. - A template class is a generic class that works with any data type; the type is given as a parameter when the object is created.
template <class T> class Box { T value; public: Box(T v) : value(v) {} T get() const { return value; } }; Box<int> a(5); // T = int Box<string> b("UOS"); // T = string - Operator overloading gives an existing operator a new meaning for user-defined types by writing an
operatorfunction, e.g.Complex operator+(const Complex&)so thatc3 = c1 + c2;works. It is a form of compile-time polymorphism. - A destructor takes no arguments and returns nothing, so there is no parameter list to distinguish two versions; an object is destroyed only once, so one destructor per class is enough.
- this pointer: a hidden pointer available in every non-static member function that holds the address of the object that called the function. It is used to resolve name clashes and to return the object itself (
return *this;).class Student { string name; public: void setName(string name) { this->name = name; // this-> refers to the member, not the parameter } }; - Inheritance – a derived class reuses the data and functions of an existing base class instead of rewriting them (composition is another reuse mechanism).
::(scope resolution),.(member access),.*(pointer-to-member),?:(conditional),sizeofandtypeid.- All member functions of class A can access the private (and protected) members of class B, because the whole class A is declared a friend of B (
friend class A;inside B). Friendship is one-way: B does not get access to A’s private members.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.
