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
43
votes
6 answers
Understanding Java's protected modifier
I have a class called A in package1 and another class called C in package2. Class C extends class A.
A has an instance variable which is declared like this:
protected int protectedInt = 1;
Here is the code for class A
package package1;
public…

mahela007
- 1,399
- 4
- 19
- 29
42
votes
3 answers
difference between protected and package-private access modifiers in Java?
I have seen various articles on differences between the protected and package private modifiers. One thing I found contradictory between these two posts
Isn't "package private" member access synonymous with the default (no-modifier) access?
In…

eagertoLearn
- 9,772
- 23
- 80
- 122
42
votes
2 answers
Protected method in python
Possible Duplicate:
Making a method private in a python subclass
Private Variables and Methods in Python
How can I define a method in a python class that is protected and only subclasses can see it?
This is my code:
class BaseType(Model):
def…

Pooya
- 4,385
- 6
- 45
- 73
41
votes
3 answers
Why can't I use protected constructors outside the package?
Why can't I use protected constructors outside the package for this piece of code:
package code;
public class Example{
protected Example(){}
...
}
Check.java
package test;
public class Check extends Example {
void m1() {
Example…

Abhilash28
- 645
- 1
- 9
- 15
40
votes
5 answers
Deletion of copy-ctor & copy-assignment - public, private or protected?
In order to make an object non-copiable we can explicitly delete both its copy-constructor and copy-assignment operator.
My question is: What is the right place to do it - in the public, private or protected section of the class? And - does this…

Sajal
- 1,783
- 1
- 17
- 21
38
votes
4 answers
Protected Classes in .NET
Can a class be protected in.NET?
Why is / isn't this possible?

Aarsh Thakur
- 587
- 3
- 10
- 20
36
votes
6 answers
how do I iterate through internal properties in c#
public class TestClass
{
public string property1 { get; set; }
public string property2 { get; set; }
internal string property3 { get; set; }
internal string property4 { get; set; }
internal string property5 {…

coder
- 4,121
- 14
- 53
- 88
36
votes
3 answers
Why can't a class or an interface receive private or protected access modifiers?
I am reading some Java text and the text says that we can only apply public or default access modifier for class and interface. Therefore, it is a compiling error if we declare:
private class A {}
or
protected class A{}
I am just curious why a…

ipkiss
- 13,311
- 33
- 88
- 123
36
votes
6 answers
Can I force abstract methods to be protected when someone overrides them?
In my abstract class, I have something like this:
public Object methodIWantToExpose(){
// ...
methodIDontWantExposed()
// ...
}
protected abstract void methodIDontWantExposed();
The thing is, I want to force the person that extends…

justsomeusername
- 495
- 4
- 11
35
votes
2 answers
Why is this Public Function in a Module not accessible
I have an assembly comprised of several useful little utilities. Within that I have a module Containing a simple Public Function.
Module FishTrackerConfigurations
Public Function GetValueOfUseProductId As Boolean
Return VtlGetUseProductId 'A…

Dom Sinclair
- 2,458
- 1
- 30
- 47
35
votes
4 answers
Changing Function Access Mode in Derived Class
Consider the following snippet:
struct Base
{
virtual ~Base() {}
virtual void Foo() const = 0; // Public
};
class Child : public Base
{
virtual void Foo() const {} // Private
};
int main()
{
Child child;
child.Foo(); // Won't work. Foo…

hlx236sk
- 353
- 1
- 3
- 4
35
votes
8 answers
Why is internal protected not more restrictive than internal?
I'd like to create an internal auto-property:
internal bool IP { get; protected internal set; }
I thought it would be possible to make the setter protected or protected internal - but I always get the error accessibility modifier must be more…

tanascius
- 53,078
- 22
- 114
- 136
34
votes
4 answers
MVVM: Should a VM object expose an M object directly, or only through getters delegating to M's getters?
the best way to explain is with example so:
this is the model
public class Person
{
public int age;
public string name;
}
this is the view model
public class PersonVM
{
}
my question is:
should the vm expose the person to the data…

Chen Kinnrot
- 20,609
- 17
- 79
- 141
33
votes
6 answers
What does the protected modifier mean?
I am reading the book The Java Programming Language, 3rd edition.
In chapter 3.5 , it illustrates the protected modifier with the following words:
More precisely, beyond being accessible within the class itself and to code within the
same…

Leem.fin
- 40,781
- 83
- 202
- 354
33
votes
4 answers
Why can't my subclass access a protected variable of its superclass, when it's in a different package?
I have an abstract class, relation in package database.relation and a subclass of it, Join, in package database.operations. relation has a protected member named mStructure.
In Join:
public Join(final Relation relLeft, final Relation relRight) {
…

Amir Rachum
- 76,817
- 74
- 166
- 248