nafiz amin
nafiz amin

Reputation: 97

What happens if you don't call the base constructor from the derived constructor?

Is it always necessary to call base class constructor from derived class constructor? What happens when you don't call it?

Upvotes: 5

Views: 4425

Answers (2)

Edward Strange
Edward Strange

Reputation: 40849

Nothing at all, since it's absolutely impossible not to do so.

Upvotes: -2

Flinsch
Flinsch

Reputation: 4341

Assuming you're talking about C++ (anyway, this should be similar in most other languages), if you don't call a constructor of the base class explicitly, its default constructor will be called automatically (if one exists; if not, the compiler would fire an error).

Upvotes: 10

Related Questions