5. Which of the following is correct?
A. Base class pointer object cannot point to a derived class object
B. Derived class pointer object cannot point to a base class object
C. A derived class cannot have pointer objects
D. A base class cannot have pointer objects
Answers
Answered by
1
Answer:
D. A base class cannot have pointer objects
Answered by
1
Answer:
From the given options, the correct option is A) Base class pointer object cannot point to a derived class object.
Explanation:
- A derived class pointer cannot point to a base class object in C++, while a base class pointer can point to a derived class object.
- Although a base class pointer can point to an object of a derived class, we can only use the base class pointer to access base class members or virtual functions because object slicing takes place when a derived class object is assigned to a base class object.
- Similar to how a base class object can be referenced by a base class pointer, a derived object is a base class object because it is a subclass.
- To a derived class pointer, a base class object cannot be allocated because it is not a derived class object.
#SPJ6
Similar questions