View RSS Feed

Java Object

Declaring Member Variables

Rate this Entry
by , 04-26-2012 at 05:12 PM (846 Views)
Various kinds of variables are present
  • Member variables which are present in a class are known as fields.
  • Variables in block of code or method are known as local variables.
  • Variables in method declarations—these are called parameters.



These code lines are used by the Bicycle class so that for defining its fields:
Java Code:
public int cadence;
public int gear;
public int speed;
There are 3 components of field declaration which are present in order, as following:

  1. More or zero modifiers like private or public.
  2. Field's type.
  3. Field's name.


Bicycle fields are known as speed, gear and cadence & all of them are (int) data type integer. They keyword public makes identification of such fields being public members which are being accessed by objects which have access of class.

Submit "Declaring Member Variables" to Facebook Submit "Declaring Member Variables" to Digg Submit "Declaring Member Variables" to del.icio.us Submit "Declaring Member Variables" to StumbleUpon Submit "Declaring Member Variables" to Google

Categories
Tutorial

Comments