View Single Post
Old 08-02-2012, 08:29 PM   PM User | #14
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You can only invoke it this way since you are writing the main method within the class itself. Create a new class with a main method and invoke the same and you will get an compilation error. I mentioned that main methods within a class are considered within a valid scope, and as such can access private properties.

This code of course wouldn't compile. MountainBicycle is not provided with a return type, nor is it a constructor for the class Bicycle. Constructors only need to be provided with the public scope if you wish to allow construction using new MyClassType(). If you do not want to allow instance creation with the new keyword, then a private/protected scope is added to prevent that.

Remember the basic scopes are: private - only this class can access, protected - only this class and its children can access, public - anything can access. The final modifier is one without an explicit access modifier, and it is best thought of as package. This page describes these modifiers: http://docs.oracle.com/javase/tutori...sscontrol.html
Note that the last line also indicates that you should not use public, even though most examples on the site do.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
tomjas (08-16-2012)