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
0
votes
2 answers

const-based function overloading accross public/protected access

(I believe) I know about overloading functions based on const-ness: if the instant is const, the const method is called, otherwise the non-const one. Example (also at ideone): #include struct S { void print() const { std::cout <<…
hcc23
  • 1,180
  • 11
  • 17
0
votes
2 answers

Omitting access specifier in java

I know that the name of the public class declared in a java file must be same as its file name. But I wonder how this is not giving me a compilation error, rather it is running successfully. class Foo //<-- this can be any name... { public…
nitish712
  • 19,504
  • 5
  • 26
  • 34
0
votes
1 answer

Accessing C++ class public member function from private struct data member

This might be a trivial C++ semantics question, I guess, but I'm running into issues on Windows (VS2010) with this. I have a class as follows: class A { public: some_type some_func(); private: struct impl; boost::scoped_ptr
squashed.bugaboo
  • 1,338
  • 2
  • 20
  • 36
0
votes
3 answers

Is it Possible to expose a private variable in c# ?

i just wanted to know Is it Possible to expose a private variable in c# ? I know if data of a class is private means is not accessible from outside class. if, yes, then how ?
Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
0
votes
1 answer

How can write method act similar to clone method of object?

I observed clone is method of Object Class and Object is super class of every class. In every class i'm getting the clone as override method, suppose i create class with name A if I'm not override clone method at class A, and created an object for A…
Sandeep P
  • 4,291
  • 2
  • 26
  • 45
0
votes
1 answer

Can't access protected class member in a derived class

The errors are: d_start is a protected member of CourseActivity duration is a protected member of CourseActivity location is a protected member of CourseActivity class CourseActivity{ protected: StartTime* d_start; double duration; …
0
votes
1 answer

Caching via static properties in PHP

I have a number of classes that extend an abstract DatabaseRecord class. Essentially, the DatabaseRecord class handles some common functions that all of the child classes use in interacting with the database (e.g. searching by id, updating,…
waiwai933
  • 14,133
  • 21
  • 62
  • 86
0
votes
1 answer

asp.net mvc 3 dependency injection ninject

I want to ask something about asp.net mvc 3 dependency injection ninject. Here is my Interface, public interface IRegistration { bool Registration(T Entity); } This is ClsMembers class. public class ClsMembers:IRegistration
0
votes
4 answers

about understanding a java code segment from its design perspective

I am trying to understand a java-based open source project, which has a code segment like protected SimpleBinaryModel(ExampleSet exampleSet, double threshold) { super(exampleSet); this.threshold = threshold; } Although I can generally guess…
0
votes
1 answer

How can you provide this access specifier protection in python?

Here is the scenario I am currently dealing with. There is a class called Service. Basically, only a single object of this can be created by a node. Once this object is created it is passed from one node to another node. Class Service: int…
appy g
  • 167
  • 4
  • 12
0
votes
1 answer

Public const variable or private with a get function, which is preferable?

So I have a variable I often have to call outside the class, I was told that I should do this: class Foo{ public: //stuff Type getVariable(); private: Type Variable; //stuff } But why can't I just use: class…
Jan M.
  • 489
  • 2
  • 5
  • 21
0
votes
1 answer

In java protected membes access from diff package

In Java, how can I access protected members in a different package? package p1 class base protected int x package p2 import p1.* class derived extends base int x class subderived extends derived int x From…
0
votes
2 answers

accessing all the private members of a class c++

I have created few class as below (Since I can not put my real class Here I have written few as just example ) class One { private : char *link; int count } class Two { private : char *link; …
Suru
  • 31
  • 1
  • 9
0
votes
1 answer

How to layer specificity

Within the posting at http://www.smashingmagazine.com/2009/08/17/taming-advanced-css-selectors/ in the context of defining the rules of 'specificity' is stated: For example, if you want to change the background color of all the div elements…
justSteve
  • 5,444
  • 19
  • 72
  • 137
0
votes
2 answers

How to make private property accessible in MVC3

I'm using Mvc3 and NHibernate I have a class called Activation code like following: public virtual int LoginAccountId { get; set; } protected virtual string ActivatedCode { get; set; } protected virtual DateTime ActivationDate { get; set; } I want…
priya77
  • 175
  • 2
  • 10
  • 24