您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
Content Index
Content Page # 4 

Compound statements

Notice that some statements consist of more than a single line of the source file. For example the class declaration statement actually consists of the entire contents of the TicketDiscount.java source file. Likewise, the control statement 'if( age >= 60 ) ...' actually includes the statement 'System.out.println("qualifies for discount");' as well.

A compound statement is one that consists of a group of statements that are preceded with an open brace "{", and the last statement in the group followed by a close brace "}".

In the example there are 3 compound statements. The first is the class declaration itself:

class TicketDiscount

{

... // rest of class 

}

The second is the declaration of the main() method:
public static void main( String args[] )

{

// rest of method

}

The third is the set of statements to be executed if the test of age is true:
if( age >= 60 )

{

System.out.println( age + "is 60 or over" );

System.out.println("qualifies for discount");

}

This example also illustrates how compound statements can be nested, i.e. the if statement is a statement within the compound statement that is the implementation of the main() method:
public static void main( String args[] )

{

...

  if( age >= 60 )

    {

    System.out.println( age + "is 60 or over" );

    System.out.println("qualifies for discount");

    }

}
 
                                                       Back to top

basicline.gif (169 bytes)

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