Question 1
What is encapsulation in C++?
Wrapping data and functions into a single unit
Hiding the class from the user
Binding UI elements to data
Using inheritance to reuse code
Question 2
Which access specifier provides the highest level of protection?
private
protected
public
None of the above
Question 3
Which access specifier allows inheritance but restricts direct access?
protected
private
public
None of the Above
Question 4
What is the main benefit of encapsulation in C++?
Faster execution
Better UI design
Data security and abstraction
Simplified syntax
Question 5
What will be the output of the following code?
class Test {
private:
int x;
public:
void setX(int val) { x = val; }
};
int main() {
Test obj;
obj.setX(10);
cout << obj.x;
return 0;
}
10
0
Garbage Value
Compilation Error
Question 6
What does this code achieve in terms of encapsulation?
class Student {
private:
int roll;
public:
void setRoll(int r) { roll = r; }
int getRoll() { return roll; }
};
Data hiding but no encapsulation
Encapsulation without data hiding
Both encapsulation and data hiding
None of the above
There are 6 questions to complete.