About Question enthuware.ocpjp.v11.2-.-1770 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ACV001
Posts: 9
Joined: Fri Sep 11, 2015 9:13 am
Contact:

About Question enthuware.ocpjp.v11.2-.-1770 :

Post by ACV001 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.1770 :

Post by admin »

Please copy the code exactly as given in the problem statement. There is no "types" defined in Food class.
If you like our products and services, please help us by posting your review here.

ACV001
Posts: 9
Joined: Fri Sep 11, 2015 9:13 am
Contact:

Re: About Question enthuware.ocpjp.v11.2-.-1770 :

Post by ACV001 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2-.-1770 :

Post by admin »

If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests