OOP PAST PAPER FALL-2023
OOP PAST PAPER FALL-2023
OOP PAST PAPER FALL-2023
No, access identifiers (like public, private & protected) in most programming languages cannot
be changed during runtime. There are a few reasons for this:
Security: Access modifiers define the intended access level of a class member (variable,
method). Changing them at runtime could lead to security vulnerabilities by exposing
data or functionality that wasn't meant to be public.
Code Stability: The code relies on the defined access levels to function correctly. If
access levels could change dynamically, the code's behaviour would be unpredictable and
difficult to maintain.
Design Principles: Access modifiers are a core concept in object-oriented programming
(OOP) that promotes encapsulation and data hiding. Changing them would violate these
principles.
No, destructors cannot be overloaded in C++. A class can only have one destructor.
Example:
class Math {
return x * x;
}
};
In this example:
Resolution: Determined by the compiler at compile time based on the object's declared
type.
Mechanism: Achieved through method overloading.
Method Overloading: Multiple methods exist within the same class with the same name
but different parameter lists (number, type, or order of parameters). The compiler chooses
the appropriate method based on the arguments used in the function call.
Example:
#include <iostream>
using namespace std;
cout<<age<<endl;
cout<<name<<endl;
cout<<salary<<endl;
main(){
showInfo(24);
showInfo(“HAMZA AFZAL”);
showInfo(25000.52);
Example:
#include <iostream>
using namespace std;
class A{
public:
Virtual void disp(){
};
class B : public A{
public:
};
main(){
A *ptr;
B obj;
ptr = &obj;
ptr->disp();
LONG QUESTION:
#include <iostream>
using namespace std;
class Binary{
private:
int x;
int y;
public:
Binary(){
x = 1;
y = 0;
};
};
return 0;
x = a;
y = b;
};
x = a.x;
y = b.y;
};