Questions tagged [access-modifiers]

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

1041 questions
3652
votes
31 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
  • 38,099
  • 4
  • 24
  • 21
795
votes
20 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
  • 21,709
  • 30
  • 113
  • 139
632
votes
7 answers

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

What is the equivalent of Java's final in C#?
Nosrama
  • 14,530
  • 13
  • 49
  • 58
495
votes
22 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
  • 33,874
  • 33
  • 95
  • 118
481
votes
7 answers

Internal vs. Private Access Modifiers

What is the difference between the internal and private access modifiers in C#?
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
456
votes
10 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
  • 29,607
  • 57
  • 139
  • 219
316
votes
19 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
  • 189,012
  • 314
  • 712
  • 1,047
292
votes
16 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
  • 40,904
  • 21
  • 118
  • 94
276
votes
12 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
  • 16,125
  • 37
  • 97
  • 135
162
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
162
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
  • 40,644
  • 36
  • 176
  • 219
159
votes
9 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
  • 2,056
  • 2
  • 16
  • 17
155
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
  • 10,411
  • 33
  • 99
  • 165
152
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
  • 17,693
  • 24
  • 96
  • 176
138
votes
4 answers

Initializer is inaccessable due to 'internal' protection level

I have a protocol LoginStrategy public protocol LoginStrategy { func login(_ viewController: UIViewController) func getUserInfo(withCompletionHandler completionHandler: @escaping (_ userInfo: [String: Any]?) -> ()) func…
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
1
2 3
69 70