Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public keyword

 
Alexander Kamarov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second one cannot be accessed from outside the package.
 
Alexander Kamarov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it the same case for classes?


 
Waldemar Macijewski
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15494
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic