This link has been bookmarked by 7 people . It was first bookmarked on 27 Mar 2007, by Mukesh Soni.
-
24 Aug 09
-
Member variables in a class—these are called fields
-
Variables in a method or block of code—these are called local variables
-
method declarations
-
parameters
-
- Zero or more modifiers, such as
publicorprivate. - The field's type.
- The field's name.
- Zero or more modifiers, such as
-
publicmodifier—the field is accessible from all classes.privatemodifier—the field is accessible only within its own class.
-
We still need access to these values, however. This can be done indirectly by adding public methods that obtain the field values for us
-
private int cadence; private int gear; private int speed;
-
public int getCadence() { return cadence; } public void setCadence(int newValue) { cadence = newValue; }
-
-
10 Feb 09
-
- There are several kinds of variables:
- Member variables in a class—these are called fields.
- Variables in a method or block of code—these are called local variables.
- Variables in method declarations—these are called parameters.
-
- Field declarations are composed of three components, in order:
- Zero or more modifiers, such as
publicorprivate. - The field's type.
- The field's name.
- Zero or more modifiers, such as
-
-
publicmodifier—the field is accessible from all classes. -
privatemodifier—the field is accessible only within its own class.
Access Modifiers
The first (left-most) modifier used lets you control what other classes have access to a member field. For the moment, consider onlypublicandprivate. Other access modifiers will be discussed later.In the spirit of encapsulation, it is common to make fields private.
-
-
Types
All variables must have a type. You can use primitive types such asint,float,boolean, etc. Or you can use reference types, such as strings, arrays, or objects. -
- the first letter of a class name should be capitalized, and
- the first (or only) word in a method name should be a verb.
In this lesson, be aware that the same naming rules and conventions are used for method and class names, except that
-
-
27 Mar 07
-
modifier used lets you control what other classes have access to a member field.
-
publicmodifier—the field is accessible from all classes.-
privatemodifier—the field is accessible only within its own class.
-
- the first letter of a class name should be capitalized, and
- the first (or only) word in a method name should be a verb.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.