About Question enthuware.ocpjp.v7.2.1770 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

About Question enthuware.ocpjp.v7.2.1770 :

Post 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

Luiz Paro
Posts: 3
Joined: Wed Jan 29, 2014 5:42 pm
Contact:

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

Post 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).

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You are right. Fruit should say extends Food as well. This has now been fixed.
thank you for your feedback!
Paul.

Gustavo Brossi
Posts: 1
Joined: Sat Aug 01, 2015 12:07 pm
Contact:

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

Post by Gustavo Brossi »

Still not fixed.

Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Danny Sheridan
Posts: 30
Joined: Sat May 02, 2015 4:48 pm
Contact:

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

Post by Danny Sheridan »

Ah sorry, missed the Question bank update

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest