| Author |
public keyword
|
emil gasanov
Greenhorn
Joined: Jul 14, 2012
Posts: 6
|
|
Hi everyone, just a little noobish question: is there a difference between
and
And if there is, what it it? Is omitting the "public" keyword makes any difference to the availability of the method?
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
|
The second one cannot be accessed from outside the package.
|
The quieter you are, the more you are able to hear.
|
 |
emil gasanov
Greenhorn
Joined: Jul 14, 2012
Posts: 6
|
|
Is it the same case for classes?
|
 |
Waldemar Macijewski
Ranch Hand
Joined: Jun 22, 2012
Posts: 32
|
|
emil gasanov wrote:Is it the same case for classes?
Yes. Classes can be declared without any access modifiers, the "default" access modifier means that this class will be visible only within current the package.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
emil gasanov wrote:Is it the same case for classes?
Yes it is. The only difference is with interfaces. If you omit access modifier in method signatures of interface, they are still all public.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12924
|
|
|
The topic Controlling Access to Members of a Class in Oracle's Java Tutorials explains exactly what the difference is between public, protected, private and no access modifier.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: public keyword
|
|
|