This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ambigious Interface solution?

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code creates an ambigious situation for the class .... it complies sucessfully but bot return any value..Anyone please tell me why it happen so ... and if i want to remove this ambiguity what I have to do?

Thanks
Kaustubh
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaustubh G Sharma wrote:it complies sucessfully

No it doesn't. When I compile it:

and if i want to remove this ambiguity what I have to do?

Since both a.x and b.x are public static final you can use those names: a.x and b.x.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code doesn't compile at all.

You wrote "Interface" and "Class" with capital letters in lines 1, 6 and 10, and you can't put a System.out.println(...); statement at class level, as you are doing in line 11.

Please PostRealCode, not pseudo-code that doesn't really work, because that will confuse the question. It's important to be precise.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhm yeah. I fixed those issues already when trying, but Jesper is right. We should be able to copy-paste your code and try for ourselves without having to fix any issues that you don't have (like fixing the issues Jesper mentioned).
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And always better to avoid Ambiguous situations.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Kaustubh G Sharma wrote:it complies sucessfully

No it doesn't. When I compile it:



Sorry Boss My mistake it is also not compiling at my side also...I got ambiguity in words also...
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry people please don't go on syntax....it was not copy paste i just typed it here...
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Kaustubh!

Champ, look at what Rob said: "Since both a.x and b.x are public static final you can use those names: a.x and b.x.". This solves your problem.

Other than that, you have an instruction (System.out.println(x)) in a place of the class where it is not expected. You can put it in a static block:



or in a method:

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roberto now my doubt has been cleared
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic