I wrote this code in the main:
if (startAmount>0) //create new cashier object with or without a start amount
Cashier newCashier = new Cashier(startAmount);
else Cashier newCashier = new Cashier();
and got an compile error for the second and third lines:
Multiple markers at this line
- Cashier cannot be resolved to a variable
- Syntax error on token "newCashier", delete
and:
Multiple markers at this line
- Cashier cannot be resolved to a variable
- Syntax error, insert "AssignmentOperator Expression" to complete
Assignment
- Syntax error, insert ";" to complete Statement
but when i write the code like this with brackets:
if (startAmount>0)//create new cashier object with or without a start amount
{
Cashier newCashier = new Cashier(startAmount);
}
else{ Cashier newCashier = new Cashier();}
it seems to be okay, no compile errors. can someone help me understand why?
newCashieranyway.