Page 1 of 1

About Question enthuware.ocajp.i.v7.2.944 :

Posted: Thu Mar 27, 2014 1:16 pm
by __Bill
I think I have found a mistake in the explanation for this question.

Chaining to use a value of a variable at the time of declaration is not allowed. Had b and c been already declared, it would have been valid. For example, the following is valid:   
int  b = 0, c = 0;   
int a = b = c = 100;
Even the following is valid:   
int  b , c;  //Not initializing b and c here.   
int a = b = c = 100; //declaring a and initializing c, b, and a at the same time. Notice the order of initialization of the variables - c is initialized first, b is initialized next by assigning to it the value of c. Finally, a is initialized.


------ Okay, never mind. I see that the two pairs of lines go together in the explanation, iow two examples total not four.

Re: About Question enthuware.ocajp.i.v7.2.944 :

Posted: Fri Oct 31, 2014 3:10 pm
by afigan
public class Test {
int a,b,c; a = b = c = 100;
}
gives

>javac Test.java
Test.java:2: error: <identifier> expected
int a,b,c; a = b = c = 100;
^
1 error

Re: About Question enthuware.ocajp.i.v7.2.944 :

Posted: Fri Oct 31, 2014 8:23 pm
by admin
Afigan, you need to put it in a method. Problem statement has now been updated to make it clear.
thank you for your feedback!