I have a 3 questions on overloaded constructors:
1.On the line marked line 1,
I am calling an overloaded constructor but the compiler doesn't resolve the call,
is there something else I need to do?
On the line marked with a 2, The compiler complains that the "this()" needs to be the first statement in the method, when it is. What's with that?
If I am writing an overloaded constructor, and I haven't overridden the default constructor do I need an explicit "this();" in the overloaded constructor, if i want to execute the behavior of the default constructor, or is it included in all constructors for "free"?
.
class JavaSnippet {
public static void main(String[] args) {
String MenuItemName="Coffee";
double MenuItemPrice=1.0;
Item MenuItem;
//1-> MenuItem=new Item(MenuItemName,MenuItemPrice);// Get "cannot find symbol"
}
}
class Item {
String name;
double price;
public void Item(String InName, double InPrice) {
// 2-> this();// get "call to this must be first statement in constructor"
name=InName;
price=InPrice;
}
}