Explain the purpose of a Constructor. Can a Constructor be inherited or overridden?
Last updated
A constructor's purpose is to initialize a new object into a valid state. Constructors are not inherited and cannot be overridden: they are tied to the specific class that declares them.
Purpose: Allocate/initialize fields, enforce invariants, and accept required dependencies at creation time.
Not inherited: A subclass does not receive its parent's constructors as its own; you must declare the subclass's own constructors (and they call
super(...)).Not overridden: Overriding requires the same name and polymorphic dispatch; constructors are name-bound to their class and are not virtual, so they can be overloaded but never overridden.
Related caution: Calling an overridable method from a constructor is risky: the subclass override may run before the subclass is fully initialized.
- https://www.igmguru.com/blog/oops-interview-questions
- https://tryrehearsal.ai/technical-questions/explain-oops-concepts
- https://github.com/Devinterview-io/oop-interview-questions
- https://www.hirist.tech/blog/top-30-c-oops-interview-questions-and-answers/
- https://www.interviewbit.com/oops-interview-questions/
- https://blog.stackademic.com/dont-just-code-the-15-essential-practices-senior-developers-want-you-to-learn-now-84246fb2f6ed
- https://www.reddit.com/r/ExperiencedDevs/comments/1mpaewh/how_should_i_deal_with_junior_devs_that_debate/
- https://www.scaler.com/topics/oops-concepts-in-cpp/
- https://javatechonline.com/interview-questions-object-oriented-programming/
- https://henko.net/blog/my-favorite-interview-questions/
- https://utkrusht.ai/blog/python-interview-questions
- https://www.digitalocean.com/community/tutorials/oops-interview-questions-answers
- https://www.scribd.com/document/510810151/Fragile-base-class