O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.1. Access modifiers

Java has four categories of protection access for methods and variables:

  • private

  • protected

  • (default, or package – no access modifier specified)

  • public.

C# has five categories of protection access:[1]

[1] If you have done C++ before, you might have heard of C++'s friend keyword. Both Java and C# have discarded the 'friend function' feature of C++. friend is not a keyword in both Java and C#.

  • private

  • protected

  • internal

  • internal protected

  • public.

Java's default (also known as package) accessibility is no longer there, and there is a new accessibility category based on the internal modifier in C#.

Table 8.1 shows more information about C#'s accessibility options.

Table 8.2 shows the applicable accessibility modifiers for the various ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required