📄 appb.htm
字号:
('extends' InterfaceName (',' InterfaceName)*)?<BR> '{' FieldDeclaration* '}'<BR>;</TT></BLOCKQUOTE><P>Interface declarations are similar to classes. The main differencebetween them is that interface declarations can extend one ormore existing interfaces.<BLOCKQUOTE><TT>FieldDeclaration =<BR> DocComment? MethodDeclaration<BR>| DocComment? ConstructorDeclaration<BR>| DocComment? VarableDeclaration<BR>| StaticInitializer<BR>| ';'<BR>;</TT></BLOCKQUOTE><P>DocComment is an undefined terminal. It takes the form of a multilinecomment beginning with <TT>/**</TT>and ending with the standard <TT>*/</TT>.<BLOCKQUOTE><TT>MethodDeclaration =<BR> Modifier* Type Identifier '(' ParameterList? ')' ('[' ']' )*<BR> ( '{' Statement* '}' | ';' )<BR>;</TT></BLOCKQUOTE><P>Grammars enable syntactic constructs that cause the compiler toissue semantic errors. Notice that the body of a method is optional.Syntactically, this is correct. Semantically, however, this iscorrect only if a native or abstract modifier is present.<BLOCKQUOTE><TT>ConstructorDeclaration =<BR> Modifier* Identifier '(' ParameterList? ')'<BR> '{' Statement* '}'<BR>;<BR>VariableDeclaration =<BR> Modifier* Type VariableDeclarator (',' VariableDeclarator)*';'<BR>;<BR>VariableDeclarator =<BR> Identifier ('[' ']')* ('=' VariableInitializer)?<BR>;</TT></BLOCKQUOTE><P>A variable declarator may specify an array: <TT>intname[]</TT>. It also is legal for a Type to specify anarray: <TT>int[] name</TT>. Eitherform is correct.<BLOCKQUOTE><TT>VariableInitializer =<BR> Expression<BR>| '{' (VariableInitializer ( ',' VariableInitializer )* ','? )?'}'<BR>;</TT></BLOCKQUOTE><P>The second rule is for array initializations:<BLOCKQUOTE><TT>int x[] = { 1, 2, 3, 5, 9 };</TT></BLOCKQUOTE><P>The preceding statement creates an array of integers with a lengthof 5.<BLOCKQUOTE><TT>StaticInitializer =<BR> 'static' '{' Statement* '}'<BR>;</TT></BLOCKQUOTE><P>You used a static initializer in <A HREF="ch10.htm" >Chapter 10</A>,"Native Methods and Java," to load a native library:<BLOCKQUOTE><TT>ParameterList =<BR> Parameter (',' Parameter)*<BR>;<BR>Parameter =<BR> Type Identifier ('[' ']')*<BR>;<BR>Statement =<BR> VariableDeclaration<BR>| Expression ';'<BR>| '{' Statement* '}'<BR>| 'if' '(' Expression ')' Statement ('else' Statement)?<BR>| 'while' '(' Expression ')' Statement<BR>| 'do' Statement 'while' '(' Expression ')' ';'<BR>| 'for' '(' (VariableDeclaration | Expression ';' | ';')<BR> Expression?';' Expression?')' Statement<BR>| 'try' Statement ('catch' '(' Parameter ')' Statement)*<BR> ('finally' Statement)?<BR>| 'switch' '(' Expression ')' '{' Statement* '}'<BR>| 'synchronized' '(' Expression ')' Statement<BR>| 'return' Expression? ';'<BR>| 'throw' Expression ';'<BR>| 'case' Expression ':'<BR>| 'default' ':'<BR>| Identifier ':' Statement<BR>| 'break' Identifier? ';'<BR>| 'continue' Identifer? ';'<BR>| ';'<BR>;</TT></BLOCKQUOTE><P>Unlike C, break and continue have an optional identifier. Thisenables branching to a label. <TT>For</TT>loops may declare a new variable just as in C++. Notice that eachloop expression is optional.<P>Several control statements (<TT>if</TT>,<TT>while</TT>, and <TT>for</TT>)specify an expression in parentheses. Semantically, the expressionmust evaluate to a boolean type or an error is issued.<BLOCKQUOTE><TT>Expression =<BR> Expression '+' Expression<BR>| Expression '-' Expression<BR>| Expression '*' Expression<BR>| Expression '/' Expression<BR>| Expression '%' Expression<BR>| Expression '^' Expression<BR>| Expression '&' Expression<BR>| Expression '|' Expression<BR>| Expression '&&' Expression<BR>| Expression '||' Expression<BR>| Expression '<<' Expression<BR>| Expression '>>' Expression<BR>| Expression '>>>' Expression<BR>| Expression '=' Expression<BR>| Expression '+=' Expression<BR>| Expression '-=' Expression<BR>| Expression '*=' Expression<BR>| Expression '/=' Expression<BR>| Expression '%=' Expression<BR>| Expression '^=' Expression<BR>| Expression '&=' Expression<BR>| Expression '|=' Expression<BR>| Expression '<<=' Expression<BR>| Expression '>>=' Expression<BR>| Expression '>>>=' Expression<BR>| Expression '<' Expression<BR>| Expression '>' Expression<BR>| Expression '<=' Expression<BR>| Expression '>=' Expression<BR>| Expression '==' Expression<BR>| Expression '!=' Expression<BR>| Expression '.' Expression<BR>| Expression ',' Expression<BR>| Expression 'indtanceof' ( ClassName | InterfaceName )<BR>| Expression '?' Expression ':' Expression<BR>| ''++'' Expression<BR>| ''-''Expression<BR>| '++' Expression<BR>| '-'Expression<BR>| Expression '++'<BR>| Expression '-'<BR>| '-' Expression<BR>| '!' Expression<BR>| '~' Expression<BR>| '('Expression ')'<BR>| '(' Type ')' Expression<BR>| Expression '(' ArgList? ')'<BR>| 'new' ClassName '(' ArgList? ')'<BR>| 'new' TypeSpecifier ( '[' Expression ']' )+ ('[' ']')*<BR>| 'new' '(' Expression ')'<BR>| 'true'<BR>| 'false'<BR>| 'null'<BR>| 'super'<BR>| 'this'<BR>| Identifier<BR>| Number<BR>| String<BR>| Character<BR>;</TT></BLOCKQUOTE><P>Comparison expressions always evaluate to a boolean expression.<P>Declaring new arrays can be confusing. The syntax states thatthere must be a <TT>new</TT> keywordfollowed by a type and one or more defined dimensions: <TT>newint[2][3]</TT>. A trailing undefined dimension is alsoallowed: <TT>new int[2][3][]</TT>.The following is not legal because there must be one or more defineddimensions: <TT>new int[]</TT>.<BLOCKQUOTE><TT>ArgList =<BR> Expression (',' Expression )*<BR>;<BR>Type =<BR> TypeSpecifier ('[' ']')*<BR>;</TT></BLOCKQUOTE><P>Here is the second method for declaring an array: <TT>int[]name</TT>.<BLOCKQUOTE><TT>TypeSpecifier =<BR> 'boolean'<BR>| 'byte'<BR>| 'char'<BR>| 'short'<BR>| 'int'<BR>| 'float'<BR>| 'long'<BR>| 'double'<BR>| ClassName<BR>| InterfaceName<BR>;<BR>Modifier =<BR> 'public'<BR>| 'private'<BR>| 'protected'<BR>| 'static'<BR>| 'final'<BR>| 'native'<BR>| 'synchronized'<BR>| 'abstract'<BR>| 'threadsafe'<BR>| 'transient'<BR>;<BR>PackageName =<BR> Identifier<BR>| PackageName '.' Identifier<BR>;<BR>ClassName =<BR> Identifier<BR>| PackageName '.' Identifier<BR>;<BR>InterfcaeName =<BR> Identifer<BR>| PackageName '.' Identifier<BR>;</TT></BLOCKQUOTE><P><HR WIDTH="100%"></P></P></CENTER><P><HR WIDTH="100%"></P><!-- reference library footer #1--></CENTER><IMG SRC="/images/rule.gif" WIDTH="460" HEIGHT="5" VSPACE="5"ALT="Ruler image"><br><FONT SIZE="-1">Contact <a href="mailto:reference@developer.com">reference@developer.com</a> with questions or comments.<br><a href="/legal/">Copyright 1998</a> <a href="http://www.earthweb.com" target="_top">EarthWeb Inc.</a>, All rights reserved.<BR>PLEASE READ THE <a href="/reference/usage.html">ACCEPTABLE USAGE STATEMENT</a>.<BR>Copyright 1998 Macmillan Computer Publishing. All rights reserved.</FONT></BLOCKQUOTE><!--outer table--><TD VALIGN="TOP"><!--right side ads --><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCAD1.REF" alt="Click here for more info"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCAD1.REF" alt="Click here for more info" height="88" width="88" border="0"></a><P><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCAD2.REF" alt="Click here for more info"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCAD2.REF" alt="Click here for more info" height="88" width="88" border="0"></a><P></td></tr></table></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -