Questions tagged [access-modifiers]

Access modifier is an OOP concept. It determines what level of access or visibility a particular property/method/class has.

966 questions
3352
votes
29 answers

What is the difference between public, protected, package-private and private in Java?

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance?
intrepion
  • 34,999
  • 4
  • 21
  • 21
751
votes
17 answers

In C#, what is the difference between public, private, protected, and having no access modifier?

All my college years I have been using public, and would like to know the difference between public, private, and protected? Also what does static do as opposed to having nothing?
MrM
  • 20,601
  • 29
  • 103
  • 136
587
votes
7 answers

What is the equivalent of Java's final in C#?

What is the equivalent of Java's final in C#?
Nosrama
  • 13,592
  • 12
  • 46
  • 56
444
votes
23 answers

Practical uses for the "internal" keyword in C#

Could you please explain what the practical usage is for the internal keyword in C#? I know that the internal modifier limits access to the current assembly, but when and in which circumstance should I use it?
Alexander Prokofyev
  • 32,090
  • 32
  • 91
  • 115
416
votes
7 answers

Internal vs. Private Access Modifiers

What is the difference between the internal and private access modifiers in C#?
Jim Fell
  • 12,390
  • 29
  • 117
  • 192
414
votes
9 answers

What are the default access modifiers in C#?

What is the default access modifier for classes, methods, members, constructors, delegates and interfaces?
Surya sasidhar
  • 27,349
  • 55
  • 130
  • 212
280
votes
17 answers

Does Swift have access modifiers?

In Objective-C instance data can be public, protected or private. For example: @interface Foo : NSObject { @public int x; @protected: int y; @private: int z; } -(int) apple; -(int) pear; -(int) banana; @end I haven't found any…
Gergo Erdosi
  • 36,694
  • 21
  • 106
  • 90
270
votes
18 answers

Are there any reasons to use private properties in C#?

I just realized that the C# property construct can also be used with a private access modifier: private string Password { get; set; } Although this is technically interesting, I can't imagine when I would use it since a private field involves even…
Edward Tanguay
  • 176,854
  • 291
  • 683
  • 1,015
253
votes
11 answers

What is the difference between 'protected' and 'protected internal'?

Can someone please explain the difference between the protected and protected internal modifiers in C#? It looks like their behavior is identical.
Embedd_0913
  • 14,911
  • 33
  • 93
  • 133
161
votes
5 answers

Does Java have a "private protected" access modifier?

I have seen some references refer to a access modifier in Java called private protected (both words together): private protected someMethod() { } One of the pages I found referring to this is here. My school lesson also referred to this access…
user6754053
148
votes
2 answers

Which access modifiers are implied when not specified?

For all of the different concepts that support access modifiers, such as fields, properties, methods and classes, which access modifiers are implied if not specified?
Sam
  • 35,545
  • 30
  • 157
  • 202
142
votes
2 answers

Why does Typescript use the keyword "export" to make classes and interfaces public?

While dabbling with Typescript I realised my classes within modules (used as namespaces) were not available to other classes unless I wrote the export keyword before them, such as: module some.namespace.here { export class SomeClass{..} } So now…
Grofit
  • 15,299
  • 19
  • 84
  • 167
134
votes
13 answers

What is the default access modifier in Java?

What is the default access modifier for a method or an instance variable if I do not state it explicitly? For example: package flight.booking; public class FlightLog { private SpecificFlight flight; FlightLog(SpecificFlight flight) { …
yrazlik
  • 9,023
  • 26
  • 84
  • 145
133
votes
6 answers

What is the meaning of the planned "private protected" C# access modifier?

As part of the Roslyn documentation on GitHub, there's a page called Language feature implementation status, with planned language features for C# and VB. One feature I couldn't wrap my head around was private protected access modifier: private…
Kobi
  • 125,267
  • 41
  • 244
  • 277
125
votes
7 answers

"Private" (implementation) class in Python

I am coding a small Python module composed of two parts: some functions defining a public interface, an implementation class used by the above functions, but which is not meaningful outside the module. At first, I decided to "hide" this…
oparisy
  • 1,717
  • 2
  • 14
  • 16
1
2 3
64 65