Access level modifiers determine whether other classes can use a particular field or invoke a particular method.
Questions tagged [access-levels]
85 questions
5
votes
8 answers
C# protected field to private, add property--why?
In Visual Studio 2008 Team System, I just ran Code Analysis (from the Analyze menu) on one of my C# projects. One of the warnings produced was the following:
Microsoft.Design : Because field 'Connection._domain' is visible outside of its declaring…

Sarah Vessels
- 30,930
- 33
- 155
- 222
4
votes
1 answer
Swift: Calling function from a different target
I have two targets (Target A, Target B) and from Target B I would like to call a function which is located in Target A. I get the Use of Unresolved Identifier error when trying to compile as expected since ClassA.swift isn't part of Target B. So I…

Bhavik Patel
- 41
- 5
3
votes
1 answer
Extension initializer is inaccessible due to 'internal' protection level swift 4
I have a convenience initializer in an extension inside my framework.
And I want to use it in another extension in my project.
It granted public access to everything I could but the compiler keeps saying "initializer is inaccessible due to…

The Windwaker
- 1,054
- 12
- 24
3
votes
2 answers
Swift enum case access level
I know, that Swift does not allow redefinition of the access level of a case in a enum, meaning the following is not possible
public enum Foo {
private case Bar
private indirect case Ind(Foo)
public init() {
self = Bar
…

tierriminator
- 587
- 5
- 19
3
votes
4 answers
How to restrict access to a nested class to its container in C#?
I have a configuration class store application configuration. Currently I am using a static class. Some of the configurations are related to one topic so I want to organize them into a nested class, so I can reference configurations like…

codewarrior
- 723
- 7
- 22
3
votes
2 answers
C# compile error: “X is inaccessible due to its protection level”
when c# gives this compile error?
'Favorite.Favorites.FavoriteCollection' is inaccessible due to its protection level
private void Form1_Load(object sender, EventArgs e)
{
Favorites objFavorites = new Favorites();
…

Arash
- 3,013
- 10
- 52
- 74
3
votes
5 answers
Java Protected Access Not Working
In java, there's three levels of access:
Public - Open to the world
Private - Open only to the class
Protected - Open only to the class and its subclasses (inheritance).
So why does the java compiler allow this to happen?
TestBlah.java:
public…

Anton
- 1,387
- 2
- 17
- 30
3
votes
1 answer
Overriding operators within nested internal classes
I need to override the Equals operator (and therefore, the GetHashcode method) in a nested class whose accessibility is internal.
When I try to do this, the compiler complains that I can't override Equals - a public member - with a private method.…

Cardinal Fang
- 283
- 2
- 12
3
votes
2 answers
How to make VS assume everything is public by default
I use VS2012 and ReSharper 7 to write C# code. My projects are rarely so large or complicated as to require thinking about granular access levels. It's usually easier for me to just make everything public, instead of spending time and effort to…

Superbest
- 25,318
- 14
- 62
- 134
3
votes
2 answers
What access level should loggers be set to?
I'm using SLF4J with Log4J underneath. What access levels should I be setting my loggers to?
static final Logger logger = LoggerFactory.getLogger(ClassName.class);

James McMahon
- 48,506
- 64
- 207
- 283
2
votes
1 answer
"Best" way to access IO.FileInfo Protected property (OriginalPath)?
I'm working on a series of methods that will test a given path to determine if it is (or, at least could be) valid. I have a couple of overloads that will accept either an IO.FileInfo object or an IO.DirectoryInfo object - which I'd personally…

G_Hosa_Phat
- 976
- 2
- 18
- 38
2
votes
1 answer
Why can't I access Internal/Friend properties from a dynamic object?
I'm going to show VB.NET code first because the behavior of its C# equivalent is more confusing (see below).
Consider the following three classes:
Public Class BaseClass
Private Shared Rand As New Random
Public Shared Function…

41686d6564 stands w. Palestine
- 19,168
- 12
- 41
- 79
2
votes
1 answer
Swift classes with generics allow superclasses to be inaccessible
In an iOS framework, if I create a public class with an internal superclass, I get an error:
internal class Animal { }
public class Dog: Animal {
var name: String
public init(name: String) {
self.name = name
}
}
Error: Class…

William Key
- 173
- 12
2
votes
0 answers
Laravel 5 and Angular 2 Authorization
I used Laravel 5.3 as the back-end language and angular 2 as front-en.
My question is when the user logged into system how determine current user access list and how angular detects that the user can't access current route or specific section of…

Zahra Eslami
- 51
- 3
2
votes
2 answers
Error with C++ partial specialization of template
I am using PC-Lint (great tool for static code analysis - see http://www.gimpel.com/)
For the following chunk of code:
class ASD {
protected:
template
void foo();
};
template<>
inline void ASD::foo<1>() {}
template

ssobczak
- 1,795
- 3
- 18
- 28