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 .

94 questions
31
votes
3 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
  • 333
  • 1
  • 3
  • 5
15
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,072
  • 1
  • 14
  • 16
13
votes
4 answers

Calling a Controller function in another Controller in CodeIgniter

I have a controller "user" in my codeigniter application. This controller has a function called logged_user_only(): public function logged_user_only() { $is_logged = $this -> is_logged(); if( $is_logged === FALSE) { …
Roman
  • 3,704
  • 20
  • 48
  • 70
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
  • 691
  • 6
  • 22
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

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
  • 36,703
  • 18
  • 113
  • 134
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,039
  • 2
  • 14
  • 57
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,649
  • 10
  • 28
8
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
7
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,392
  • 13
  • 55
  • 59
5
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
  • 342
  • 1
  • 13
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
  • 6,654
  • 2
  • 32
  • 59
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
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
  • 9,379
  • 17
  • 60
  • 114
1
2 3 4 5 6 7