Confusion regarding access specifiers in Java and C #

I compared access modifiers in Java and C #. I wanted to find an alternative to C # protected internalin Java. But I noticed that the modifier protectedis different in both languages ​​( C # and Java ). protectedin Java is equivalent protected internalfor C # because a member accesses it in the same package.

I have two questions

  • Why did they create different values ​​for the same modifier in Java and C #?
  • How can I use protectedfor C # (access is limited to the contained class or types derived from the containing class.) In Java?
+5
source share
2 answers

Java #?

. Java () # .

# ( , .) Java?

. Java .

, , protected, . , , , -, . , ( ).

, , , . , , .

:

enter image description here

+2

Java API Sun.com.

D:\>javac Demo.java
Demo.java:1: error: **modifier** private not allowed here
private class Test
        ^
1 error
0

All Articles