Questions tagged [access-specifier]

The access specifier in an object-oriented language determines how a class restricts access to its members.

The access specifier in an object-oriented language determines how a class restricts access to its members.

The usual access specifiers are private, protected and public.

  • A class member whose access specifier is private can only be used by instances of that class.
  • A class member whose access specifier is protected can only be used by some other classes.
    Usually this means that access to these members is granted only to subclasses, but this is not a hard-and-fast rule. In Java, for example, classes that are in the same package also have access to each other's protected members.
  • A class member whose access specifier is public can be used by all other classes in the program.

You can use this tag for questions about how access to the members of your class is resolved.

242 questions
-1
votes
1 answer

friend function is not a friend of all template instances?

In the following example I try to access the private member function subscribe() from a templated class type from within its friend function. However it appears that the friend function is only befriended in one instantiation of the class and not…
glades
  • 3,778
  • 1
  • 12
  • 34
-1
votes
5 answers

How to differentiate between the private instance variable and a parameter having same name in java

There is a keyword this in java to access the instant variables which are public. But is there such way to access the private ones class Foo { private int a = 2; public int b = 3; public void test(int a, int b) { this.b = b; …
-1
votes
1 answer

Difference between internal and moduleprivate in Swift

I am not able to understand what is the difference between these two keywords in swift3? If anyone has a link to a good article about this, please share.
Nikita P
  • 4,226
  • 5
  • 31
  • 55
-1
votes
1 answer

Why virtual functions defy access specifiers ? C++

let's assume u have a class base and class A which inherits from base . base have a declaration of a pure virtual functions called getValue() which is public , and A contains the definition(implementation) of the functions which is set as private…
-1
votes
1 answer

private javax.swing.JTextField3; error

I greatly thanks those that reply to my question "main method not found error", after correcting all the parenthesis and it seem the code is alright.On the IDE its still indicate the error below; private javax.swing.JButton jButton1; …
Olumide
  • 11
  • 3
-2
votes
0 answers

How does class and objects enable data hiding when constructors, setters and getters are all public?

While the internet offers examples as given below when learning CPP: #include class Employee { private: int salary; public: Employee() : salary(0){ } Employee(int s) : salary(s){ } Employee(const Employee& ref) :…
-2
votes
2 answers

variable visibility from calling function

I have 2 classes. In one class i have 4 variables. I instantiate another class and use methods which use these variables. I dont want to pass them as parameters. They are set to public. Both classes are in the default package with each other. heres…
xxsurajbxx
  • 13
  • 2
-2
votes
2 answers

Why is an internal static string is not accessible from outside the class?

I have a class defined as follows: class Foo { internal string IString; internal static string IstaticString; public Foo() { IstaticString = "static"; IString = "non - static"; } …
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
-2
votes
3 answers

Why interface variable or field more precise are not default?

I mean to say that Why cannot I have it default access specifier and please don't tell me that java developer made it like that I know that this link it give me that information ..My real Question why it cannot be default access specifier? Not…
-3
votes
1 answer

does declaring a variable as private show any difference from declaring it as final while inheritance

EDIT: sorry for the inconvenience, it was lack of understanding of the concept. u can simply ignore this question. i am pretty sure that we can't inherit neither final nor private variables. but, why should we declare variables as final when…
-3
votes
1 answer

Java access specifier issue

I am confused with access specifiers in Java.. I have a code with 2 different packages in Java.. But it displays an error every time I run it.. Here's is the code for the class which is calling the class using import from another package.. package…
Akshit Gupta
  • 109
  • 1
  • 8
-3
votes
1 answer

Accessing a variable from an unrelated function in C++

I want to access a variable of one class into another class, and set it to some value, e.g. like in code here, i wanna set the some_flag to true in the secondClassFunction(). Is it possible? If yes, how to do it? Constraints due to system…
cappy0704
  • 557
  • 2
  • 9
  • 30
-3
votes
1 answer

Creating class operator

Trying to create class operator: class ggg { int a; int b; operator std::string ( ) { return "hello"; } }; int main() { ggg g ; std::string s = g; cout<
vico
  • 17,051
  • 45
  • 159
  • 315
-3
votes
4 answers

Do not want to set private to default in Java

I have this in one class: if (people.count < 10) return false; But count is undermarked with red saying Change the visibility of count to default count is in another class as private. But I don't want to change it to default. I know it is a…
Sam
  • 900
  • 10
  • 18
-4
votes
2 answers

C# internal Access Specifiers,

I have Created one ConsoleApplication to understand Access Specifiers. Below is my code for internal, I can access this class from outside the Assembly. namespace Assembly_1 //This is first assembly. { public class Base { …
Bharat
  • 5,869
  • 4
  • 38
  • 58
1 2 3
16
17