Reputation: 33
Lets say I have couple of classes and I am trying to call one of the methods in my super class and this error happens. I am not able to understand why?
File1:
public class A extends B {
public A(int arg1){
this(arg1, new class_C(getMethod())); // Throws error here
}
public A(int arg1, int arg2){
super(arg1) ;
}
}
File2:
public class B{
public B(int arg1){
super(arg1) ;
}
public int getMethod() { return 100;}
}
Thanks for your help.
Upvotes: 0
Views: 67
Reputation: 193
In java, the constructor must be called firstly. In your code, the getMethod in the B class is called before its' constructor is called. If this was allowed in java, it would messed up it's initialization.
Upvotes: 1