Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.581 :

Posted: Wed Feb 02, 2011 8:57 pm
by ETS User
Which of the lines will cause a compile time error in the following program?

Code: Select all

public class MyClass
{
   public static void main(String args[])
   {
      char c;
      int i;
      c = 'a';//1
      i = c;  //2
      i++;    //3
      c = i;  //4
      c++;    //5
   }
}
for answer option 3, "The line 3", you state:
'i' is not initialized.
.. Why did you mention this? The code does not compile,as you stated, because of line 4. And, 'i' is set at line 2.
????

Re: About Question com.enthuware.ets.scjp.v6.2.581 :

Posted: Thu Feb 03, 2011 6:18 am
by admin
I don't see any reason why that comment should be there. i is initialized at //2. The detailed explanation says, "2. Line 4 will not compile because it is trying to assign an int to a char. Although the value of i can be held by the char but since 'i' is not a constant but a variable, implicit narrowing will not occur."

It should be removed.

thank you,
Paul.