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.
About Question enthuware.ocajp.i.v7.2.944 :
Moderators: Site Manager, fjwalraven
-
- Posts: 25
- Joined: Thu Mar 27, 2014 11:35 am
- Contact:
-
- Posts: 1
- Joined: Fri Oct 31, 2014 3:06 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.944 :
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
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
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.944 :
Afigan, you need to put it in a method. Problem statement has now been updated to make it clear.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 25 guests