Hi, I'm new to Java, getting compiler error for the following code:

class A {
int x;
A (int a) {System.out.println ("class A");}
}

class B extends A{
int x;
B() {System.out.println ("class B");}

public static void main (String[] args) {
A a= new B();
}
}

The compiler error I get is:
A(int) in A cannot be applied to ()
B() {System.out.println ("class B");}
^

Can somebody tell me how to fix it in class B?

B's constructor doesn't have an explicit call to the superclass constructor, so the compiler inserts a default one, ie super();
But the superclass doesn't have a default constructor A()
Either add a call the A's constructor in B's constructor, or add a default (no args) constructor to A

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.