+ 1
java
I have found this code https://code.sololearn.com/cA1a1a248a16 and I don't really understand why when I create the 'c' variable using new the constructor is not called? It is called only if I use c.First_C();.
4 Antworten
+ 4
Because you have not defined a constructor for the class.
public void First_C() {
System.out.println("Constructor");
}
This is a method and not a constructor.
Constructor doesn't have a return type.
+ 1
The declaration
public void First_C()
specifies a type (void) and therefore it is not a valid constructor declaration. A constructor does not declare type. It should be:
public First_C()
+ 1
Oh I haven't seen that is public void.
0
Ya I also