• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

cant see where its going wrong

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
knowledge is the difference between drudgery and strategic action -- tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic