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.
			
			
									
									
						About Question enthuware.ocpjp.i.v11.2.3200 :
Moderators: Site Manager, fjwalraven
- 
				Dani1515
 - Posts: 9
 - Joined: Mon Feb 17, 2020 12:10 pm
 - Contact:
 
- 
				Dani1515
 - Posts: 9
 - Joined: Mon Feb 17, 2020 12:10 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.i.v11.2.3200 :
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
			
			
									
									
						var x=10; would work
- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.i.v11.2.3200 :
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!
			
			
									
									
						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 :
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 ...
			
			
									
									
						but i thought when I made my wrong answer "final int x " is unchangeable, so it a constant not a variable ...
Who is online
Users browsing this forum: No registered users and 24 guests