View RSS Feed

Java Object

Overriding with constructors

Rate this Entry
by , 04-26-2012 at 06:53 PM (5342 Views)
  • A constructor canít be overridden in a superclass, because they are non-inherited.
  • A constructor canít be overridden in similar class because both of them would have similar signatures and compiler error would be there.
  • When a subclass object is instantiated & a method is called by superclass constructor which in superclass gets overridden, superclass constructor will be calling the subclass methods.

Java Code:
class Super {
        System.out.println("In Super constructor");
    void test() {
        System.out.println("In Super.test()");

class Sub extends Super {
    Sub() {
        System.out.println("In Sub constructor");
    void test() {       // overrides test() in Super
        System.out.println("In Sub.test()");

Submit "Overriding with constructors" to Facebook Submit "Overriding with constructors" to Digg Submit "Overriding with constructors" to Submit "Overriding with constructors" to StumbleUpon Submit "Overriding with constructors" to Google