What is the access specifier that allows constructors to be called only from member functions of the same class and its derived classes in C++?
A. protected
B. public
C. private
D. friend
Answer: Option C
Solution (By Examveda Team)
In C++, the access specifier that allows constructors to be called only from member functions of the same class and its derived classes isprivate. When a constructor is declared as private, it cannot be accessed from outside the class, limiting its invocation to member functions of the same class and its derived classes.Option A:
protected allows access to member functions and data members from within the same class, derived classes, and friend classes, but it still allows derived classes to call constructors, which might not be desired in some cases.Option B:
public allows unrestricted access to the constructor from anywhere, defeating the purpose of restricting its usage to only member functions of the same class and its derived classes.Option D:
friend allows non-member functions or external classes to access private and protected members of a class, but it doesn't restrict the calling of constructors to member functions of the same class and its derived classes.Therefore, the correct answer is Option C: private.
Join The Discussion
Comments (1)
A. A function used to create objects
B. A special member function that initializes objects
C. A function used to access class members
D. None of the above
Which access specifier allows constructors to be called from anywhere in the program in C++?
A. friend
B. protected
C. public
D. private
What happens if a class does not explicitly declare any constructors in C++?
A. A compilation error occurs
B. The class cannot be instantiated
C. The class is initialized with default values
D. A default constructor is provided by the compiler
What is the purpose of a destructor in C++?
A. A special member function that destroys objects
B. A function used to create objects
C. A function used to initialize objects
D. A function used to access class members

The access specifier that allows constructors to be called only from member functions of the same class and its derived classes in C++ is:
A. protected