ExamVeda
Login
Home
21
What is the term for a function that is declared inside a class but defined outside of it in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
22
What is the process of wrapping data and functions into a single unit called in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
23
What is the purpose of the 'this' pointer in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
24
What is the purpose of using constructors in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
25
What is a constructor in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
26
Which keyword is used to create a copy constructor in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
27
What is the purpose of a copy constructor in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
28
Which access specifier allows members of a class to be accessed only by member functions of the same class and its derived classes in C++?
Discuss
Answer & Solution
Answer: Option A
Solution:
Access specifiers in C++ determine the visibility and accessibility of class members.

The protected access specifier allows members of a class to be accessed by:

1. Member functions of the same class

2. Member functions of its derived (child) classes

This makes protected different from private, which restricts access only to the class itself, and from public, which allows access from anywhere.

Now let’s see why the other options are incorrect:

Option B: public — Members are accessible from anywhere in the program, which is more permissive than required by the question.

Option C: private — Members are accessible only within the same class, not by derived classes, so this is too restrictive.

Option D: friend — friend is not an access specifier; it is a keyword used to allow a specific external function or class to access private or protected members of another class. It doesn’t define a general access level.

Conclusion: The protected access specifier is the one that allows class members to be accessed within the same class and its derived classes.

Hence, the correct answer is Option A: protected.
29
What happens if a class does not explicitly declare any constructors in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
30
What is a destructor in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board