If a constructor is defined in protected access, then?

Đức Lưu

New member
If a constructor is defined in protected access, then?
A. It’s instance can be created inside the subclasses
B. It’s instance can be created anywhere in the program
C. It’s instance can be created inside the subclasses and main() function
D. It’s instance can be created inside the parent class only
 
Answer: a
Explanation: The instances will be allowed to be created only inside the sub classes. This is because the protected members will be inherited and hence the constructor too. This will allow the subclasses to call the constructor whenever an object is created.
 

Tìm kiếm

Back
Top