aspose file tools*
The moose likes Beginning Java and the fly likes public keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public keyword" Watch "public keyword" New topic
Author

public keyword

Alexander Kamarov
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: 825
    
    5

The second one cannot be accessed from outside the package.


The quieter you are, the more you are able to hear.
Alexander Kamarov
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: 825
    
    5

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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14270
    
  21

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 8 API documentation
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: public keyword