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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

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

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

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

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