• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

public declaration in methods

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
Is the public keyword the regarded as a default when defining methods. I have a class that contains only methods that I wish to call from another file/class. I have methods as shown below :
int getClose() {
return this.closeTime ;
}

void setClose(int closeTime) {
this.closeTime = closeTime ;
}
This compiles and runs fine. But I have also seen that if you declare the methods as public int getClose() and public void setClose(int closeTime), it also works fine. The only difference is that in the latter I have added the keyword public to the method definition.
So, because both versions work fine, can I assume that the keyword public is a default definition.
Thanks In Advance,
Rajesh
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, public is not the default.
If you omit the access specifier, the default access (sometime referred to unimaginatively as 'default access', but also termed 'package protected') acts as if you specified the protected access specifier but also makes the element available to classes in the same package.
Non-extending classes outside the package will have no access to the element.
hth,
bear
[ June 08, 2003: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you omit the access specifier, the default access (sometime referred to unimaginatively as 'default access', but also termed 'package protected') acts as if you specified the protected access specifier but also makes the element available to classes in the same package.
package private Bear. Classes outside the package do not have access not even subclasses which have access to all protected methods. Protected methods are also available to the whole package.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops! Right. Brain fart!
wiping egg off face,
bear
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic