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
18
votes
5 answers

public static final variable in an imported java class

I happen to come across a Java code at my work place. Here's the scenario: There are 2 classes - ClassA and ClassB. ClassA has nothing except 4 public static final string values inside it. Its purpose is to use those values like ClassA.variable…
Senthil Kumar
  • 9,695
  • 8
  • 36
  • 45
17
votes
6 answers

Properties vs Public member variables

Possible Duplicate: What is the difference between a field and a property in C# I'm a beginning programmer and I've read all about class properties. Books state that properties allow you to indirectly access member variables. Ok, so what makes it…
user1230593
  • 243
  • 1
  • 3
  • 9
16
votes
1 answer

Public fields for Java compatibility

I found recent interest in Kotlin as a language, because the platform we develop for is Java 6 based and hence lacks any syntactic sugar the recent years brought to Java. There's but one thing that makes it impossible to use Kotlin over Java in…
John Smith
  • 752
  • 9
  • 35
16
votes
4 answers

Closest Ruby representation of a 'private static final' and 'public static final' class variable in Java?

Given the Java code below, what's the closest you could represent these two static final variables in a Ruby class? And, is it possible in Ruby to distinguish between private static and public static variables as there is in Java? public class…
Hosh
  • 225
  • 1
  • 2
  • 7
15
votes
2 answers

How to setup public git repositories?

I recently tried to setup git repo on a linux box and wasted about 10 hours with absolutely no results. There aren't any problems with compilation or anything like that, it's just configuration issue. 2 hours later I got mercurial to do everything i…
alex
  • 2,036
  • 2
  • 16
  • 19
15
votes
2 answers

Why Junit test cases(Methods) should be public?

I just want to know why the test cases (test methods) should be public like this public class SpiceLoginTest { @Test public void testShouldVerifyLoginRequest() { } } but if I remove public access specifier from this method @Test …
Gurinder
  • 943
  • 2
  • 9
  • 19
15
votes
1 answer

Does it make a difference whether I put 'friend class xxxxx' in the public or private section?

class A1 { public: friend class B; } class A2 { private: friend class B; } Any difference?
Kyle
  • 4,487
  • 3
  • 29
  • 45
15
votes
2 answers

What is the difference between export and public in typescript?

I think this is a different slant on this question. And maybe the question is better phrased, when would you use public, as opposed to export? From my reading it seems like anywhere a C#/Java person thinks public, what you actually want is…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
14
votes
2 answers

Do you ever use protected visibility in Rails?

Confession: I only use private and public visibility for my methods! I have a feeling this is a bad thing. But in Rails it just doesn't seem to come up as an issue. Does anyone have an example in Rails where it would be a big mistake not to use…
pez_dispenser
  • 4,394
  • 7
  • 37
  • 47
14
votes
2 answers

Saving public files in the internal storage

I have an application that saves files downloaded from a server. These files are not private to my application and should be accessible to other applications as well. I want to know what would be the correct path to save these files when the SD card…
Akshay
  • 5,747
  • 3
  • 23
  • 35
14
votes
2 answers

Assign LAN IP address to Docker container different from host's IP address

Am not well versed with Unix networking, adding virtual interfaces etc, trying to learn it now. We are trying to dockerize our application. My requirement is : To assign an ip to a docker container which is accessible from an external…
Blue Sky
  • 807
  • 1
  • 15
  • 36
14
votes
6 answers

Does static method in PHP have any difference with non-static method?

class t { public function tt() { echo 1; } } t::tt(); See?The non-static function can also be called at class level.So what's different if I add a static keyword before public?
user198729
  • 61,774
  • 108
  • 250
  • 348
13
votes
3 answers

C# override public member and make it private

Possible? Can you change the access of anything to anything else?
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
13
votes
3 answers

Making classes public to other classes in C++

If I have two classes for example as follows: class A {...} class B {...} If I want to make class A public to class B, do I just make the members of class A public or I can just use public class A {...}? Is there a way to tell class B for example…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
13
votes
12 answers

What are the alternatives to public fields?

I am programming a game in java, and as the question title suggestions i am using public fields in my classes. (for the time being) From what i have seen public fields are bad and i have some understanding why. (but if someone could clarify why you…
James
  • 215
  • 1
  • 2
  • 7