Why do I get a 'constructor is undefined` error?

Jaja

Why would the following code yield a compilation error (The constructor AA() is undefined)? Shouldn't it call a default constructor?

public class A{
    public A(){ }
}

public class AA extends A{
    public AA(int aa){ }
}

public class C{
    public static void main(String[] args){
        A a= new AA();
    }
}
CKing

The compiler will only add a default constructor to a class if there is no constructor in the class which is not the case for AA.

8.8.9 Default Constructors (Java language specification)

If a class contains no constructor declarations, then a default constructor is implicitly declared

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive