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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
__Bill
Posts: 25
Joined: Thu Mar 27, 2014 11:35 am
Contact:

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

Post 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.

afigan
Posts: 1
Joined: Fri Oct 31, 2014 3:06 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests