Page 1 of 1

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

Posted: Sun Apr 18, 2021 5:36 am
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     
}
}

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

Posted: Sun Apr 18, 2021 8:11 am
by admin
Please copy the code exactly as given in the problem statement. There is no "types" defined in Food class.

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

Posted: Sun Apr 18, 2021 3:03 pm
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

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

Posted: Sun Apr 18, 2021 5:14 pm
by admin