Page 1 of 1
About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Jul 28, 2015 4:41 pm
by Danny Sheridan
Code: Select all
interface Eatable {
int types = 10;
}
class Food implements Eatable {
public static int types = 20;
}
public class Fruit implements Eatable {// LINE1
public static void main(String[] args) {
types = 30; // LINE 2
System.out.println(types); // LINE 3
}
}
Compilation failure at //LINE 1 as well as at //LINE 3
Class Fruit implements Eatable as well as extends Food.
Fruit does not extend Food in the given code
Shouldn't the answer be: Compilation failure at //LINE 2 ?
javac returns:
Fruit.java:13: error: cannot assign a value to final variable types
types = 30; // LINE 2
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Jul 28, 2015 7:40 pm
by Luiz Paro
I've noticed that too, even if you force Fruit class to extend from Food, then the compile error happens on lines 2 and 3 for the given explanation on the question (ambiguous reference).
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Jul 28, 2015 8:09 pm
by admin
You are right. Fruit should say extends Food as well. This has now been fixed.
thank you for your feedback!
Paul.
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Sat Aug 01, 2015 12:09 pm
by Gustavo Brossi
Still not fixed.
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Aug 04, 2015 5:07 am
by Danny Sheridan
Hi Paul,
(This might just be a typo error but just to let you know)
With the intended code in place the correct answer of
compilation errors at both
LINE 2 and LINE 3 is not present
although the explanation is correct
Having changed the code to declare the Fruit class as:
Code: Select all
public class Fruit extends Food implements Eatable
javac doesn't now return compilation errors at //LINE 1 and //LINE 3
javac:
C:\Users\admin\Desktop\pad n compiler\pad n compiler 5>javac Fruit.java
Fruit.java:9: error: reference to types is ambiguous, both variable types in Food and variable types in Eatable match
types = 30; //LINE 2
^
Fruit.java:10: error: reference to types is ambiguous, both variable types in Food and variable types in Eatable match
System.out.println(types); //LINE 3
^
2 errors
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Aug 04, 2015 5:45 am
by admin
I am not sure I understand you correctly. I see that option 7 (the correct option) is "Compilation failure at //LINE 2 as well as at //LINE 3" and this is what you get when you try to compile it.
-Paul.
Re: About Question enthuware.ocpjp.v7.2.1770 :
Posted: Tue Aug 04, 2015 8:24 am
by Danny Sheridan
Ah sorry, missed the Question bank update