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.

1509 questions
3352
votes
29 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
  • 34,999
  • 4
  • 21
  • 21
1050
votes
17 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
  • 51,803
  • 63
  • 138
  • 208
271
votes
10 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,476
  • 9
  • 44
  • 73
185
votes
6 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,185
  • 3
  • 23
  • 35
157
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,140
  • 3
  • 16
  • 23
142
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
  • 15,299
  • 19
  • 84
  • 167
71
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
  • 134,265
  • 53
  • 250
  • 293
65
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
64
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…
58
votes
8 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
  • 1,718
  • 2
  • 28
  • 37
53
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
  • 785
  • 1
  • 7
  • 11
52
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
  • 35,191
  • 41
  • 141
  • 211
51
votes
1 answer

Call-time pass-by-reference has been removed

Possible Duplicate: Call-time pass-by-reference has been deprecated While it may be documented somewhere on the internet, I cannot find a solution to my problem. Since the PHP 5.4 update, pass-by-references have been removed. Now I have a…
Sam Smith
  • 627
  • 1
  • 5
  • 6
46
votes
9 answers

C# public variable as writeable inside the class but readonly outside the class

I have a .Net C# class where I need to make a variable public. I need to initialize this variable within a method (not within the constructor). However, I don't want the variable to be modifieable by other classes. Is this possible?
MikeTWebb
  • 8,461
  • 25
  • 86
  • 129
45
votes
4 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
  • 992
  • 2
  • 12
  • 32
1
2 3
99 100