2

Let say I have a class:

class A {
    A() {
        System.out.print("constructor of A class");
    }
}

class B extends A {

    A() {
        // why i am not override super class constructor?
    }

    public static void main(String a[]) {

    }
}

Why I am not able to override super class constructor?

Pshemo
  • 118,400
  • 24
  • 176
  • 257
manish rawat
  • 101
  • 1
  • 1
  • 7

2 Answers2

0

In java constructor is not inherited.

Refer this question: Why constructors can not be inherited in java?

Community
  • 1
  • 1
Touchstone
  • 5,144
  • 7
  • 38
  • 48
  • 2
    Don't give link to the question in answer if your are not going to add some new information , mark duplicate instead !! – Neeraj Jain Apr 15 '15 at 11:18
0

In java Constructors cannot be overridden or inherited. They cannot be called virtually. What can be done is calling super class constructor from child class constructor using super()

Isuru Gunawardana
  • 2,667
  • 5
  • 25
  • 57