1

Can we have constructor in abstract class ?

If yes, what the use of that because we can't instantiate the Abstract class and constructor will never call.

  • "Constructor" is not really good name. It suggests that it is responsible for constructing (creating) object, but it is not really true. `new` keyword is responsible for creating (uninitialized) object, constructor code is responsible for *initializing* (setting up) that object. So constructor in abstract class is part of initialization process only, which can be part of constructing *subclass* instance. – Pshemo May 02 '18 at 14:49
  • 2
    Rohit - Don't get the impression from Pshemo's comment above that **you've** used the term incorrectly. You haven't. It's just that the term itself is slightly-incorrect when viewed from a Java (or several other languages) perspective, `initializer` would have been a better term (for the reasons he/she gives). But it's not the term that got used. :-) – T.J. Crowder May 02 '18 at 14:56
  • Thanks @T.J.Crowder – Rohit Aggarwal May 02 '18 at 14:58

2 Answers2

2

Yes. The implementing class can call it.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
2

Yes.

For inheritance. So the sub class can use it.

xingbin
  • 27,410
  • 9
  • 53
  • 103