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
3652
votes
31 answers

What is the difference between public, protected, package-private and private in Java?

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance?
intrepion
  • 38,099
  • 4
  • 24
  • 21
1131
votes
16 answers

What is the difference between public, private, and protected?

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them? Examples: // Public public $variable; public function doSomething() { // ... } // Private private…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
312
votes
12 answers

Why use a public method in an internal class?

There is a lot of code in one of our projects that looks like this: internal static class Extensions { public static string AddFoo(this string s) { if (s == null) { return "Foo"; } return…
bopapa_1979
  • 8,949
  • 10
  • 51
  • 76
203
votes
7 answers

Github (SSH) via public WIFI, port 22 blocked

I'm currently on a public WIFI spot and I'm unable to use SSH (they probably blocked that port). However, I need that connection to do a git push. ➜ ssh -T git@github.com ssh: connect to host github.com port 22: Connection refused Is it possible to…
sougonde
  • 3,438
  • 3
  • 26
  • 35
176
votes
4 answers

Friend declaration in C++ - difference between public and private

Is there a difference between declaring a friend function/class as private or public? I can't seem to find anything about this online. I mean the difference between: class A { public: friend class B; }; and class A { private: //or nothing…
BIU
  • 2,340
  • 3
  • 17
  • 23
152
votes
2 answers

Why does Typescript use the keyword "export" to make classes and interfaces public?

While dabbling with Typescript I realised my classes within modules (used as namespaces) were not available to other classes unless I wrote the export keyword before them, such as: module some.namespace.here { export class SomeClass{..} } So now…
Grofit
  • 17,693
  • 24
  • 96
  • 176
92
votes
8 answers

What is the difference between 'open' and 'public' in Kotlin?

I am new to Kotlin and I am confused between open and public keywords. Could anyone please tell me the difference between those keywords?
Sagun Raj Lage
  • 2,326
  • 2
  • 18
  • 28
84
votes
5 answers

Public and Internal members in an Internal class?

Ok, so this may be a bit of a silly question, and there's certainly the obvious answer, but I was curious if I've missed any subtleties here. Is there any difference in terms of visibility/usability between a public member declared in an internal…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
73
votes
4 answers

Advantage of set and get methods vs public variable

Possible Duplicate: Why use getters and setters? Is there any advantage to making methods to access private variables in your class instead of making the variable public? For example is the second case better than the first? //Case 1 public class…
70
votes
3 answers

Class vs. Public Class

What is the difference between: namespace Library{ class File{ //code inside it } } and: namespace Library{ public class File{ //code inside it } } So what will be the difference between public class and class?
user1678541
69
votes
9 answers

Is it possible to declare a public variable in vba and assign a default value?

I want to do this but it won't compile: Public MyVariable as Integer = 123 What's the best way of achieving this?
David
  • 2,101
  • 2
  • 32
  • 41
61
votes
7 answers

'public static final' or 'private static final' with getter?

In Java, it's taught that variables should be kept private to enable better encapsulation, but what about static constants? This: public static final int FOO = 5; Would be equivalent in result to this: private static final int FOO = 5; ... public…
Chris Cummins
  • 935
  • 1
  • 8
  • 12
59
votes
2 answers

What is the c# equivalent of public final static in java

In Java I can write: public final static MyClass foo = new MyClass("foo"); Is there any equivalent in C#?
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
58
votes
1 answer

How do I make an Rust item public within a crate, but private outside it?

I have a crate that has lots of code, so I've split it into multiple files/modules. However, some modules have internal unsafe stuff (e.g. raw pointers) that I need to make public to the different modules, but I don't want to expose to users of my…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
53
votes
5 answers

Find the list of Google Container Registry public images

Where can I find the list of GCR public images? In case of docker images, we can list it in hub.docker.com. But I couldn't find anything like that for GCR.
Sujai Sivasamy
  • 1,101
  • 3
  • 14
  • 32
1
2 3
99 100