Java - expanding release

Hey guys, I have time with the problem of “extensions” with a problem in the set of problems I'm working on - I think I just have a block because it is written to purposefully mislead, Here's the problem I gave:

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();
    }
}

When I compile, I get the following error ripped from the console:

cannot find symbol
symbol  : constructor A()
location: class A
   B() {System.out.println(" class B");}
       ^

and I should be able to correct this error in class B without touching class A. I obviously lack something stupid obvious, but I tried permuting everything that I can think about for an hour and not working,

So far I have tried:

  • throws a void before B () - the same error.
  • creating B () in (int a) - the latter returns with an invalid declaration of the method declaration (adding a void in front of it returns me to the original error "cannot find character")
  • B() B (int a) - " ", B().
  • B A B A (int A) - . , .
  • A Apple , , - A (int a) Apple, .

? , , . .

+3
4

. , - , .

, :

B() {
    super(0);
    System.out.println(" class B");
}
+5

B- (a); , B.

+2

1) , , , . . , , , , .. A.A(). - A.A(int).

, B, A :

B() {
    super(42); 
    // because we are calling the constructor that takes an int, we must supply
    // one. It up to you to figure out what values should be supplied. Maybe 
    // you wanted to take an int in the B constructor, and pass it along?
    System.out.println(" class B");
}

2) int x;, A, B. , , , . , B int x - , , B A.

+1

A , ( , int).

B default-no-arg. , , A .

0

Source: https://habr.com/ru/post/1778659/


All Articles