Jump to content


Photo

Interface Question


  • Please log in to reply
2 replies to this topic

#1 wunderwaffe

wunderwaffe

    Active Member

  • Members
  • PipPip
  • 26 posts

Posted 25 February 2014 - 03:52 AM

Hello,

When I follow the instructions on this page, I still get errors, namely:

xxx cannot implement an interface member because it is not public

I thought the default value of methods and attributes was public? I set them as public and it removed the error.

'Bee.AlertLevel.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors

Adding the set accessor to Bee.cs fixes this but is there a reason why this isn't in the book? (p.273 only has "get" accessor for AlertLevel)

#2 AndrewStellman

AndrewStellman

    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 815 posts
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 25 February 2014 - 01:29 PM

If you leave off the access modifier, the member defaults to internal, not public. There's an explanation of this on page 315 (in the third edition).

And if there's only a get accessor specified in the interface, the property that implements it can either only have a public get accessory, a public get and private or internal set accessor, or public get and set.



Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com

#3 wunderwaffe

wunderwaffe

    Active Member

  • Members
  • PipPip
  • 26 posts

Posted 26 February 2014 - 01:44 AM

If you leave off the access modifier, the member defaults to internal, not public. There's an explanation of this on page 315 (in the third edition).

And if there's only a get accessor specified in the interface, the property that implements it can either only have a public get accessory, a public get and private or internal set accessor, or public get and set.


Cheers Andrew.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users