" Since Eatable and Food both have a static int field name types"
is it true? Is field types in Eatable static?
			
			
									
									
						About Question enthuware.ocpjp.v7.2.1770 :
Moderator: admin
- 
				Sergiy Romankov
 - Posts: 31
 - Joined: Thu Feb 19, 2015 8:25 am
 - Contact:
 
- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1770 :
Yes, all fields in an interface are public, static, and final. Even if you do not explicitly declare them so. This is OCA stuff 
Paul.
			
			
									
									
						Paul.
- 
				Cannelids
 - Posts: 25
 - Joined: Thu Jun 01, 2017 2:50 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.v7.2.1770 :
The explanation makes sense, and when I alter the code in various ways things change as I would expect, though there is an interesting ramification: if the explicit “implements Eatable” declaration is removed from LINE 1 of Fruit the compile errors disappear. I assume this is because, although the class still inherits the Food ‘true’ and, indirectly, the Eatable ‘true’, the former shadows the latter. (Consistent with this, if LINE 2 is disabled/removed, Line 3 prints the ‘shadowing’ value, 20, and it can be confirmed that Fruit still implements Eatable indirectly through Food by showing that “new Fruit() instanceof Eatable” returns ‘true’.) So while I always assumed that ‘re-declaring’ an interface in a subclass of a class that implements that interface makes no difference, it seems it can affect ‘shadowing relationships’. (Another way to get LINE 2 and 3 to compile is to add an explicit declaration of a static ‘types’ field to Fruit in the original code, so that this third ‘types’ variable now shadows the others.)
			
			
									
									
						Who is online
Users browsing this forum: No registered users and 40 guests