0
Can we use this() and super() both in the constructor ??
3 Réponses
+ 3
No, those keywords have to be first in the constructor. Since both keywords can't be first at the same time, you can't use them together.
0
could you explain what it means to be "first" in the constructor,please.??
0
When you create the constructor, it has to be the first statement. Example:
class MyClass
public MyClass(){
this();
System.out.println("other stuffs");
}
this() is first, if you put the println before this() it'll give you a compilation error. Because of that, you can't have both super() and this() because only 1 can be first
public MyClass(){
System.out.println("won't work");
this();
}
will give compile error