This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes public keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "public keyword" Watch "public keyword" New topic
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
    
    2

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
    
    2

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
    
    3

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: public keyword
 
Similar Threads
post/pre increment operator
Static
Use of static keyword
master exam question?
Display an array in a swing type box