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 ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.