About Question enthuware.ocpjp.i.v11.2.3200 :

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
Dani1515
Posts: 9
Joined: Mon Feb 17, 2020 12:10 pm
Contact:

About Question enthuware.ocpjp.i.v11.2.3200 :

Post by Dani1515 »

private var x = 10; // a wrong option

"Since 10 is an integer value, compiler will deduce the type of x to be int. However, var declarations can only be used inside a method and for loop declarations. So, the modifier private makes this option invalid." thats the description why this is wrong

according to "the book" from Mr. Deshmukh page 88: var str1 ="hello1"; is valid in static as well as intance initializers
so private var x=10; should work in instance initializers

badly i can not test it, because my jdk is on version 8 something, so im going to update it now and check it also.

Dani1515
Posts: 9
Joined: Mon Feb 17, 2020 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3200 :

Post by Dani1515 »

ok checked it, it works in intance and static initializer, but just like a local variable, and thats why "private var x=10; will not work,
var x=10; would work

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

Re: About Question enthuware.ocpjp.i.v11.2.3200 :

Post by admin »

Right, var declarations cannot be used while declaring class/instance fields. The explanation has been enhanced to make this point clear.
thank you for your feedback!

BaxLi007
Posts: 11
Joined: Wed Jun 26, 2019 12:43 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3200 :

Post by BaxLi007 »

I got the idea with the question/answers ...
but i thought when I made my wrong answer "final int x " is unchangeable, so it a constant not a variable ...

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests