aspose file tools*
The moose likes Beginning Java and the fly likes public declaration in methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public declaration in methods" Watch "public declaration in methods" New topic
Author

public declaration in methods

Greedy thomas
Ranch Hand

Joined: May 15, 2003
Posts: 37
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Oops! Right. Brain fart!
wiping egg off face,
bear
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public declaration in methods