Questions tagged [class-visibility]

In certain object-oriented programming languages, such as Java, class visibility determines the level of visibility or of accessibility of a class. For methods' or attributes' visibility, or for a more general tag on access modifiers, you might want to use the tag [access-modifiers].

In certain object-oriented programming languages, such as Java, class visibility determines the level of visibility or of accessibility of a class.

Generally the access modifiers used are: public, private or protected.

A question connected with the visibility of a class in an object-oriented programming language should use this tag.

For methods or attributes visibility, or for a more general tag on access modifiers, you might want to use the tag .

99 questions
5
votes
3 answers

Why a public constructor is not accessible via reflection

I'm confused, when executing following code: @Test public void testAccessible() throws NoSuchMethodException { Constructor constructor = LinkedList.class.getConstructor(); Assert.assertTrue(constructor.isAccessible()); } the…
Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69
5
votes
1 answer

Is it possible to show in the project view of Netbeans whether a class is public or package-private?

My team would like to be able to clearly see which classes in a package are public. Unfortunately there seems to be no visual indication of this in the Netbeans project view. Is there any way of adding the behaviour we want? If not, will the plugin…
4
votes
0 answers

Protected method not accessible from subclass

I know this has been asked before but my problem is strange and I couldn't find an answer. I have a parent class where a member is declared protected class BaseContoller { protected var presenter: G?…
Cliff Burton
  • 3,414
  • 20
  • 33
  • 47
4
votes
1 answer

How to hide sibling modules from each other in Rust?

I have a Rust module breakfast containing two sub modules egg and bacon. The breakfast module must know about egg and bacon, but the two children do not need to and therefore should not know about each other. This is what my code looks like now. The…
Anders
  • 8,307
  • 9
  • 56
  • 88
4
votes
1 answer

Kotlin: Visibility modifier changes type of anonymous object

Removing the private modifier of myScope (line 4) in the following working code will break the code. The reason for that is the changing type of myScope. Is the visibility set to private the type is: anonymous object : Scope. Without private the…
user1185087
  • 4,468
  • 1
  • 30
  • 38
4
votes
1 answer

Allowing Newtonsoft's JsonConvert access to internal getter/setters

I have a class with internal getters/setters to prevent the user from accessing this functionality (I'm working with a REST api). However, this also means that JsonConvert doesn't have access to them. How can I allow JsonConvert access to the…
user3791372
  • 4,445
  • 6
  • 44
  • 78
4
votes
3 answers

Illegal combination of modifiers: public and private

I am having an issue with the following code... /** * This class holds all of the information pertaining to * a person's name. */ public class Name { private String first, middle, last, maiden, initials, prefix, suffix; private char…
Cody Berry
  • 263
  • 3
  • 14
4
votes
4 answers

Can I restrict the visibility of C# extension methods to classes in the same assembly?

Say I have these files: MyCode.cs namespace MyCodeNamespace { public class MyClass { //OMITTED } internal static class MyExtensions { internal static void Foo(this string str) { //OMITTED } } } OtherCode.cs using…
inejwstine
  • 678
  • 1
  • 10
  • 30
4
votes
1 answer

Java subpackaging without making subpackge classes public

Say I have 20 classes in my root package. I decided to organize the classes by creating 3 subpackages under the root package. Then I put 5 classes into each of the subpackages, leaving 5 classes at the root package (because they are top level…
4
votes
1 answer

Java interfaces reduction in visibility, only NOT

Possible Duplicate: Reduce visibility when implementing interface in Java I must be missing something obvious, but i am getting: Cannot reduce the visibility of the inherited method And I don't see how. This is my interface: interface…
Lucas
  • 14,227
  • 9
  • 74
  • 124
3
votes
2 answers

C++, how to cast derived class to protected base?

I need to cast a class to its protected base: class ComplicatedOne : public Object { //Lots of funcs I don't want or need. }; class Line : protected ComplicatedOne { //Some funcs of ComplicatedOne get re-implemented or called by alias…
John
  • 6,433
  • 7
  • 47
  • 82
3
votes
1 answer

How to use reflection mechanisms to invoke a public method that resides in a base class with default visibility?

This question concerns the reflection mechanisms of the java programming language. I have an interface: package A; public interface MyInterface { public boolean doSomething(Object... parameters); } I have several implementation classes for…
3
votes
1 answer

FS0074: The type referenced through 'C.CRecord' is defined in an assembly that is not referenced. You must add a reference to assembly 'C'

Let's say I have a library (.NETStandard 2.0) named "C" that defines a type called "CRecord" (a record). Let's say I consume this library from a .NET 4.7.2 library called "B". There's a "B" type that makes use of the "CRecord" type. Now let's say I…
knocte
  • 16,941
  • 11
  • 79
  • 125
3
votes
2 answers

Can a sub-class affect visibility of virtual methods?

Let's say I have a fist class class Walker { public: Walker(); virtual ~Walker(); virtual void Step(); }; Then a second one, deriving from the former class Mecha : public Walker { public: Mecha(); virtual ~Mecha(); private: …
PypeBros
  • 2,607
  • 24
  • 37
3
votes
2 answers

Class instance creation restrictions

I have many algorithm classes that implement the same interface; another "factory" class has the responsibility to instantiate the correct algorithm class through a config param, then call the start method on that instance. I would like to restrict…
SteBert
  • 145
  • 7