top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we override constructor in Java? If yes then how, if no then why?

+3 votes
535 views
Can we override constructor in Java? If yes then how, if no then why?
posted May 2, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

No, You cannot override constructor of super class in sub class, In java overriding applicable to only instance methods as constructor in not treated as instance method it is specifically used to create object for the class

answer May 21, 2015 by Venkatesh B
0 votes

In Java, you can subclass (use extends keyword) or implement an interface.
You can also override the constructor including default constructor to write own code (generally for initialization).
Exceptions in Java are the classes that are singleton class or having private constructor, e.g Maths class.

answer May 4, 2015 by Priya Ranjan Kumar
...