Questions tagged [public]

`public` is an access-specifier in object-oriented languages; it indicates that all objects have access to the `public` field or method.

In object-oriented languages, classes specify how much access other classes can have to their members.

When a member has the public specifier, other classes have full access to that member.

Other access specifiers are protected and private.

You can use this tag for questions about how the public specifier controls (or fails to control) access to the members of a class, and questions on how it interacts with the other access specifiers.

1633 questions
25
votes
8 answers

This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)

I am trying to create a Android Application which uses 3 spinners. I keep getting this error and I can't figure out how to fix it. This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)
HeadShotNot
  • 265
  • 1
  • 3
  • 5
24
votes
3 answers

Is there a Python method to access all non-private and non-builtin attributes of a class?

I would like to call a method to give me a dict of all of the "non-private" (I use the term "private" somewhat loosely here since it does not really exist in Python) and non-builtin attributes (i.e. those that do not begin with a single or double…
andy
  • 1,399
  • 3
  • 12
  • 32
22
votes
5 answers

C++: overriding public\private inheritance

If B inherits from A using public, can B override one of the functions and force it to be private? class A { public: virtual double my_func1(int i); virtual double my_func2(int i); } class B : public A // Notice the public…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
22
votes
1 answer

How to make a public struct where all fields are public without repeating `pub` for every field?

How can I define a public struct in Rust where all the fields are public without having to repeat pub modifier in front of every field? A pub_struct macro would be ideal: pub_struct! Foo { a: i32, b: f64, // ... } which would be…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
22
votes
7 answers

Bus public transport algorithm

I am working on an offline C# application that can find bus routes. I can extract the timetable/bus/route data. I am searching for the most simple solution that will work with basic data. What algorithm can be used to find a route from bus stop…
Daniel Novak
  • 2,746
  • 3
  • 28
  • 37
21
votes
1 answer

Scala trait - Is there an equivalent of Java interface public static field?

In Java: public interface Foo { public static final int Bar = 0; } And in Scala, how can I create a trait Foo that has Bar, and I can access it as: Foo.Bar?
user942821
21
votes
2 answers

How to declare Global Variables in Excel VBA to be visible across the Workbook

I have a question about global scope and have abstracted the problem into a simple example: In an Excel Workbook: In Sheet1 I have two(2) buttons. The first is labeled SetMe and is linked to a subroutine in Sheet1's module: Sheet1 code: Option…
user2978241
  • 311
  • 1
  • 5
  • 9
21
votes
5 answers

How can I find all the public fields of an object in C#?

I'm constructing a method to take in an ArrayList(presumably full of objects) and then list all the fields(and their values) for each object in the ArrayList. Currently my code is as follows: public static void ListArrayListMembers(ArrayList list) …
junkforce
  • 543
  • 1
  • 4
  • 12
20
votes
11 answers

How to prevent public methods from being called from specific classes

I have an existing class into which I want to add a method. But I want the method to be called only from a specific method from a specific class. Is there any way that I can prevent that call from other classes/methods? For example, I have an…
Bagmita
19
votes
5 answers

How to redirect to public folder on laravel

I have this structure: My domain: www.example.com and this is my laravel's project folder: http://www.example.com/project and I would like to redirect to http://www.example.com/project/public I know this answer has been answered before but I try to…
Andres Ruales
  • 371
  • 1
  • 2
  • 12
19
votes
6 answers

Can there be two public section in a class? If yes then why ? And in which circumstances we do so?

There is something bugging me about classes. For example class A { public: A() { ..... ..... } void cleanup() { .... .... .... } public: UINT a; ULONG b; }; In the above example there are two public section. In the first…
Abhineet
  • 6,459
  • 10
  • 35
  • 53
18
votes
6 answers

Swift 3: The difference between Public and Internal access modifiers?

I read the Apple's reference about access modifiers in Swift 3. I read also about the same on stackoverflow but I didn't get an answer as the person who asked. As I understood correctly, there are four levels: Open,…
devshok
  • 737
  • 1
  • 8
  • 19
18
votes
9 answers

How to get the public IP address of the device

I found this sample code to get all local IP addresses, but I don't find an easy solution to get the public IP. A legacy class from Apple allowed to do that ... but it's legacy ...
Damien Romito
  • 9,801
  • 13
  • 66
  • 84
18
votes
3 answers

Public Static variable in excel vba

Is it possible to have a static variable declared in one procedure, and use this variable in several different procedures using Excel VBA? i.e. Public myvar as integer Sub SetVar() static myvar as integer myvar=999 end sub sub Usevar() …
Zeus
  • 1,496
  • 2
  • 24
  • 53
18
votes
8 answers

Setting public class variables

How do I set a public variable. Is this correct?: class Testclass { public $testvar = "default value"; function dosomething() { echo $this->testvar; } } $Testclass = new Testclass(); $Testclass->testvar = "another value"; …
Cudos
  • 5,733
  • 11
  • 50
  • 77