This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cant see where its going wrong  RSS feed

 
Christina Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

im not well with java yet :roll: , and i cant understand y its not compiling
thats my code


and the error is in this line
System.out.println(team.memberID);

it says


when i get rid of the interface it works, but i need the interface there!
any suggestion
Chris
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Member has a field called memberID, but the interface Team does not. So team.memberID (where team is type Team) will not work unless you explicitly cast the Team object to type Member...

((Member)team).memberID

Also, you have no instance of Member called "member" (lowercase m), so "member.characters..." has no meaning. Here again, I suspect you'll want to use your Team reference, but this would also need to be downcast...

((Member)team).characters...

The above changes will allow your code to compile, BUT you should probably take a step back and reconsider how/why you're using this interface. Does it really make sense that a Member implements the method to printMembers? This is something a Team might do, but not a Member. Instead, it seems that a Team should "have" Members, rather than a Member "being" a Team.

Once you get the bigger picture cleared up, I suggest you take a closer look at your methods in terms of what you want to pass into them and what you expect them to do for you. For example, your constructor for Member is going to assign a null reference to memberID regardless of what you pass as a String argument. Can you see why?
[ April 05, 2005: Message edited by: marc weber ]
 
Christina Smith
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks mate
lol, ur right, to be honest its not exactly my code but it contains the same error thats y i posted it... so cheers for that

Christina
[ April 06, 2005: Message edited by: Christina Smith ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!