Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 2 years ago

Discuss the relative merits of using protected access vs. using private access in base classes?

2 Answers

Relevance
  • 2 years ago
    Favorite Answer

    The comparison should be protected vs. public, not protected vs. private. "Protected" is a limited version of "public", exposing a method or field to other classes, but not all of them.

    Using protected to allow a "back door" access to what would normally be private is *not* object-oriented. It exposes object state to a using class, which breaks encapsulation.

    • Login to reply the answers
  • 2 years ago

    Sorry, not doing your homework for you.

    • Login to reply the answers
Still have questions? Get your answers by asking now.