您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 4

Defining a class in Java

The implementation of a class in Java always looks similar to the following:

class Customer

  {

// variables

  <variable1>

  <variable2>

  <variable...>

// methods

  <method1>

  <method2>

  <method...>

  }

A class defines a set of variables (technical instance variables, or fields, or attributes) and a set of methods. A class definition acts as a template for each instance of the class created when a Java program runs. When a Java program runs none, one or many instances (objects) may be created from a single class.

Classes are central to a Java program. Every program must have at least one. The program may use classes to represent real world (concrete) categories of object, or the program classes may be entirely internal (such as user interface classes like Button, MenuItem etc.) Program instructions can only exist inside methods, which are inside classes. 

The program designer decides what variables and methods to define as part of a class after analysis and modelling activities, prior to coding at a computer.

 
Declaring variables before methods
In fact it is only a convention that a class's variables are defined before its methods ?the Java compiler does not mind if they are mixed up.


Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg