About Question enthuware.ocpjp.i.v11.2.3200 :
Posted: Sat Mar 07, 2020 12:29 pm
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.
"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.