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
42
votes
4 answers

Is a class private or public by default in Java and C++?

Are classes private or public by default in Java and C++?
the_learner
  • 443
  • 1
  • 4
  • 6
18
votes
1 answer

Public Class - "is inaccessible due to its protection level. Only public types can be processed."

I am doing a test project to learn about XML serialization of an object, and I am getting an odd runtime error: namespace SerializeTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private…
Thad Blankenship
  • 2,242
  • 3
  • 16
  • 16
11
votes
3 answers

Is there any reason for public methods in a package protected class?

I wonder if it makes any difference if a method is public or package protected in a class that is package protected. class Example { public void test() {} } instead of class Example { void test() {} } I guess the maximum visibility is given by…
tangens
  • 39,095
  • 19
  • 120
  • 139
10
votes
1 answer

'public' function exposes its 'public/*package*/' parameter type SolarEdgeException

I have the following Java and Kotlin classes: package nl.friesoft.solaredgenotifier; class SolarEdgeException extends Exception { public SolarEdgeException(String s) { super(s); } } package nl.friesoft.solaredgenotifier class…
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
10
votes
2 answers

How is Spring BeanFactory able to instantiate a non-public class?

Spring newbie here. I observed that Spring was able to instantiate a non-public class (i.e. a class with default visibility) that I had defined. Can anyone tell me how Spring achieves this? Why is this allowed ?
Rahul
  • 12,886
  • 13
  • 57
  • 62
10
votes
2 answers

Why isn't java.io.Bits public?

I've done a lot with IO in Java and after looking for code to convert primitives to byte arrays and back I found source for java.io.Bits on one of the Java source code hosting websites. After a quick glance I realized it's exactly what I need,…
Nulano
  • 1,148
  • 13
  • 27
9
votes
6 answers

Can class visibility be shown on UML class diagrams?

Class visibility is an important part of object design. I have not seen any example diagrams showing non-public classes in several UML books, nor have I seen a way to show class visibility in Enterprise Architect, among other tools. Enterprise…
9
votes
3 answers

C++ Access private member of nested class

The title might be a bit misleading. I have the following problem: I have a tree consisting of leaves and internal nodes. The user should be able to store any information in the leaves and the tree has some methods which get a set of user-defined…
user1305497
8
votes
5 answers

What's the simplest way to satisfy a pure abstract method with methods from other base classes

Edit: Per some comments, by simple I mean a) less code, b) easy to maintain, and c) hard to get wrong. Edit #2: Also, using containment instead of private inheritance is not objectionable if it does indeed simplify the implementation of…
8
votes
3 answers

How to fake "visibility of class" (not of functions) in C++?

There is no feature that control visibility/accessibility of class in C++. Is there any way to fake it? Are there any macro/template/magic of C++ that can simulate the closest behavior? Here is the situation Util.h (library) class Util{…
javaLover
  • 6,347
  • 2
  • 22
  • 67
8
votes
2 answers

C++: Public member of a private nested class type

I have the following code: class Base { private: class NestedBase { public: void Do() {} }; public: NestedBase nested; }; int main() { Base b; b.nested.Do(); // line A compiles Base::NestedBase instance; //…
undermind
  • 1,779
  • 13
  • 33
6
votes
1 answer

Why are C# classes unsealed by default, when their methods are non-virtual by default?

Methods in C# are non-virtual by default. This answer to another question explains the advantage of doing it this way: Classes should be designed for inheritance to be able to take advantage of it. Having methods virtual by default means that every…
Raphael Schmitz
  • 551
  • 5
  • 19
5
votes
5 answers

Package and visibility

I'm making an SDK and I'm trying to separate classes to different packages, those classes use some other shared classes. The issue is if I made the shared classes public everyone will be able to see them, not only my classes. What's the right way to…
Jimmy
  • 10,427
  • 18
  • 67
  • 122
5
votes
2 answers

change visibility of a private java constant to test it

Having a private String constant in a java class that is used in some methods, when I want to make the test for this class, I will have to hardcode the string constant in the test because its private in the class. But if in the future the string…
fernando1979
  • 1,727
  • 2
  • 20
  • 26
5
votes
1 answer

Kotlin: How to deal with 'protected' property exposes its internal return type

Having a base class I would like it and its descendent class be visible only internally: internal abstract class BaseClass internal open class Class_A: BaseClass() internal open class Class_B: Class_A() In place where the list of Class_A (may also…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
2 3 4 5 6 7