Help and support on OCA OCP Java Programmer Certification Questions  
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
	Moderator:  admin 
			
		
				
			
				
																			
								ACV001 							 
									
		Posts:  9 		Joined:  Fri Sep 11, 2015 9:13 am 		
		
						
							
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by ACV001   »  Sun Apr 18, 2021 5:36 am 
			
			
			
			
			I have tried the example and it compiles perfectly. Can you please double check? It uses types from Food class. If you call it like Eatable.types = 30 - then you get an error that you cannot reassign final variable (which types in Eatable is).
Problem statement:
What will the following code print when compiled and run?  
Code: Select all 
interface Eatable{     int types = 10; } 
class Food implements Eatable {     public static int types = 20; } 
public class Fruit extends Food implements Eatable{  //LINE1          
 public static void main(String[] args) {         
   types = 30; //LINE 2         
   System.out.println(types); //LINE 3     
}
} 
			
			
													
					Last edited by 
ACV001  on Sun Apr 18, 2021 2:59 pm, edited 1 time in total.
									
 
			
									
						 
		 
				
		
		 
	 
	 
				
		
				
			
				
																			
								admin 							 
						Site Admin 			
		Posts:  10443 		Joined:  Fri Sep 10, 2010 9:26 pm 		
		
						
							
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by admin   »  Sun Apr 18, 2021 8:11 am 
			
			
			
			
			Please copy the code exactly as given in the problem statement. There is no "types" defined in Food class.
			
			
									
									
						 
		 
				
		
		 
	 
	 
				
		
				
			
				
																			
								ACV001 							 
									
		Posts:  9 		Joined:  Fri Sep 11, 2015 9:13 am 		
		
						
							
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by ACV001   »  Sun Apr 18, 2021 3:03 pm 
			
			
			
			
			Thanks, 
 
I've updated the question with the exact problem statement and there is a field types. 
 
However, interestingly enough, Intellij didn't report this as a compilation problem until I actually tried to run the code. 
 
When rebuild was done the following error popped up: 
 
"java: reference to types is ambiguous" 
 
So it is not a problem. Thanks
			
			
									
									
						 
		 
				
		
		 
	 
	 
				
		
				
			
				
																			
								admin 							 
						Site Admin 			
		Posts:  10443 		Joined:  Fri Sep 10, 2010 9:26 pm 		
		
						
							
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by admin   »  Sun Apr 18, 2021 5:14 pm 
			
			
			
			
			
			
			
									
									
						 
		 
				
		
		 
	 
	 
	
	
	
		
		Users browsing this forum: Bing [Bot] , Merlewaigo  and 30 guests