java - create parent instance from main method of sub class -


I try to make a basic example in the main method of subclass. It shows an error: "Constructor A can not be applied to the types given in A class A". Please tell me why my code does not work Thanks

Class A {protected int a; A (int a) {this.a = A; }} Class test extends a {public static zero main (string [] args) {int a = 10; An example = New A (A); }}

The problem is not on the line

  An example = New A (A);  

The problem is that, as you have not defined any constructor in the test, the compiler should provide one of the following forms:

  Test () {super (); }  

But this is not because superclass (A) does not have any default constructor. Therefore, you have to explicitly provide the constructor:

  test () {super (0); }  

or

  test (int i) {super (i); }  

For example.


Comments