Access modifier is an OOP concept. It determines what level of access or visibility a particular property/method/class has.
Questions tagged [access-modifiers]
1041 questions
17
votes
9 answers
Class is inaccessible due to its protection level
I have three classes. all are part of the same namespace. here are the basics of the three classes.
//FBlock.cs
namespace StubGenerator.PropGenerator
{
class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, …

scott
- 2,991
- 5
- 36
- 47
17
votes
1 answer
Partial classes and access modifier issue
According to MSDN Documentation for partial classes :
All the parts must have the same accessibility, such as public, private, and so on.
but if you create a WindowsForm application, you will have the default Form class in two partial classes.
The…

Naser Asadi
- 1,153
- 18
- 35
17
votes
3 answers
Changes in access of variables for generic classes in Java 7
Here is a simple example of some code that compiles using Java 6, but does not compile in Java 7.
public class Test {
private final int _myVar;
public Test(int myVar) {
_myVar = myVar;
}
public int…

amaidment
- 6,942
- 5
- 52
- 88
16
votes
2 answers
Java: accessing protected fields from inner class
Recently I've faced a problem getting a runtime error java.lang.IllegalAccessError when trying to access from inner class a protected field declared in outer's parent class that was loaded by a different class loader. Briefly:
Class Parent has…

Timofei Davydik
- 7,244
- 7
- 33
- 59
16
votes
2 answers
Kotlin: How to access field from another class?
package example
class Apple {
val APPLE_SIZE_KEY: String = "APPLE_SIZE_KEY"
}
Class:
package example
class Store {
fun buy() {
val SIZE = Apple.APPLE_SIZE_KEY
}
}
Error:
'APPLE_SIZE_KEY' has private access in…

Malwinder Singh
- 6,644
- 14
- 65
- 103
16
votes
3 answers
Difference between fileprivate and private extension?
Swift 3.0
I know that fileprivate access level modifier limited using of function/property to source file where it was declared and private - limited to lexical scope where was declared. But it seems that this rule not apply for extensions. E.G.…

Bohdan Savych
- 3,310
- 4
- 28
- 47
16
votes
2 answers
How to change the access modifier of a user control
I have a user control created in xaml, lets name it "View". In the View.xaml.cs I changed the access modifier for the class View to internal:
internal partial class View : ViewBase { ... }
After changing the access modifier the compiler states the…

PVitt
- 11,500
- 5
- 51
- 85
16
votes
2 answers
"Module local" access behaviour in Java 9
As a core of Jigsaw project is the Java Module System, it would be nice to have an ability to restrict access to particular program elements (classes, methods and fields) within particular module only.
It can be helpful when there are some elements…

Andremoniy
- 34,031
- 20
- 135
- 241
16
votes
3 answers
why python does not have access modifier?And what are there alternatives in python?
why python does not have Access modifier like in c#, java i.e public, private etc.what are the alternative way of encapsulation and information hiding in python.

urz shah
- 471
- 2
- 8
- 18
16
votes
2 answers
Access modifiers on interface members in C#
I am getting a compile error from the following property.
The error is:
"The modifier 'public' is not valid for this item"
public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties
{
get { return properties; }
set…

benPearce
- 37,735
- 14
- 62
- 96
15
votes
10 answers
Android Studio: "attempting to assign weaker access privileges" error on Room Database implementation
I am trying to implement room database, I have gone through steps on Official Website, and 'AppDatabase.java' file is like this:
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import…

Memduh Yılmaz
- 325
- 2
- 8
15
votes
3 answers
protected/public Inner Classes
Can someone please explain to me what is the difference between protected / public Inner classes?
I know that public inner classes are to avoid as much as possible (like explained in this article).
But from what I can tell, there is no difference…

bruno conde
- 47,767
- 15
- 98
- 117
15
votes
6 answers
Have you ever seen design with reasonable usage of protected internal access modifier?
I haven't, but I don't say there isn't one.
All of the C# developers who read this probably do know what is protected internal and when to use it. My question is simple : did you actually ever use it or worked on a successfully designed project…

Xorty
- 18,367
- 27
- 104
- 155
15
votes
1 answer
Calling a private base method from a derived class in C#
How can a derived class call a method from a base class?
Other classes should not have access on the other hand.
My situation:
I have a base class, in which I wrote a private method to register some values.
private void register(string param1, int…

Noel Widmer
- 4,444
- 9
- 45
- 69
15
votes
3 answers
Using a private variable in a inherited class - Java
Need to have more understanding about the private variables and inheritance. Earlier my understanding was if there is field in a class and when I'm inheriting the class, the fields that is not restricted by access(private variables) will be there in…

Kannan Ramamoorthy
- 3,980
- 9
- 45
- 63