Syntax diagram preliminary graphics use the following rules:
From left to right, from top to bottom, the path read syntax diagram of the row. The following symbols are used in the syntax diaphrand: >> - Indicates the beginning of a statement -> Indicate the statement Continued in the next line> - Indicate the statement from the previous line ->
Abstract keyword
Class syntax
>> - -------- - Abstract-Class-Identifier - ---------------- ->
'-public-' '-EXTENDS-CLASSTYPE-'
> - ------------------------------ - ClassBody -> <
'-IMplements-InterfacePelist-'
Method syntax
>> - ----------- - Abstract-resulttype-identifier->
-PUBLIC ----
'-protaced-'
> - (- -------------------- -) -; -> <
'-Formalparameterlist-'
Description Abstract keywords are used to create abstract classes and methods. The abstract class cannot be instantiated, and their use is to provide general information to the subclass. Abstract classes can contain anything that is included in the normal class, that is, classes and instance variables, and methods and structures with any modifiers. Only abstract classes may have abstract methods. If an abstract class contains an abstract method, then compile errors will occur. If one of the following is true, then an abstract method: it explicitly declares an Abstract method. It inherits an abstract method from its direct parent class. A direct class's parent interface declares or inherits a method of it (this must therefore be ABSTRACT) and this class has neither declaring and does not inherit an implementation method.
If the user declares that private, static, and final methods are Abstract, compile errors will appear. It is impossible to reset a private method, so an Abstract Private method will never be implemented. The Static method is always available, so there must be an implementation; the Static Abstract method will never be implemented. The Final method cannot be reset, so there is no implementation of the final Abstract method.
An abstract class can cover an abstract method by providing another abstract method declaration. This can provide a place to place document comments or declare a more restricted abnormal collection that can be thrown.
Example In the following example, abstract class MyAbStractClass has a normal method and an abstract method. This specific class MyConcreteclass inherits from MyabStractClass and provides an implementation of AbstractMethod.
Public Abstract Class myabstractclass {
Public void regularmethod () {
AbstractMethod ();
}
protected abstract void abstractMethod ();
}
Public class myconcreteclass extends myabstractclass {
Protected void abstractMethod () {
// does Something Interesting
}
}
The following codes displays legitimate and illegal use of the MyAbStractClass and MyConcreteclass classes.
// illegal. Compile Error.
MyabstractClass AbstractClass = new myabstractclass ();
// legal.
MyConcreteclass concreteclass = new myconcreteclass ();
// illegal. Protected method.
Concreteclass.AbstractMethod ();
// legal. General method.
Concreteclass.RegularMethod ();
Double Keyword Description This Double Numeric Type indicates a double-precision 64-bit IEEE 754 floating point number. A double instance variable, the default value of the class variable, and array elements is zero, that is, 0.0. The value of Double is from 4.9E-324 to 1.7976931348623157E308. A floating point numerical text is assumed to be type Double; optional, the user can use an ASCII character D or D to do their suffix. Sample users can declare a Double value, and in declaring it is a initial value: double exampleDouble = 5.0; additional Double Double-sized examples include: 1e1 2..3 0.03.14 1e-9d 1e137 int key description The int numeric type represents a binary complement integer of 32-bit with positive negative numbers. An int entry variable, the default value of the class variable, and array elements is zero, that is, 0. The value of int is the integer of closed intervals - 2147483648 to 2147483647. Sample users can declare an int value, and in the declaration it is a initial value: int example = 1000; // name of the variable is exampleint and its value is 1000 switch syntax V ------------ -------------------------------- '>> - switch - (- expression -) - {- - CASE -Constantexpression -: - BLOCKSTATEMENTS - ->
> - -------------------------- -} -> <
'-Default -: - blockStatements-' Description This Switch statement allows the user to compare one variable with different test values. It transmits control to a few statements based on an expression value in a loop. If the test value is equal to any of the CASE values, the corresponding result occurs and the BREAK statement causes the execution of the Switch statement to end. The type of Expression must be byte, short, int or long, otherwise a compilation error will appear. A Switch statement must be a block. Any statement that is immediately included may be marked with one or more cases or default tags. When the Switch statement is executed, first, the expression is evaluated. If the evaluation of Expression is suddenly completed for some reason, the Switch statement is suddenly completed because the same reason. Otherwise, execution will continue by comparing the value of Expression with each Case constant. After this, make a judgment based on the following rules:
If one of the CASE constant is equal to the value of the expression, then we say that the case matches, and all statements behind the CASE tag in the switch block, if any, if any, it is executed. If all of these statements are completed, or if there is no statement after the matching case tag, the entire Switch statement is done normally. If there is no CASE match, there is a default tag, then all statements behind the Default tag that match in the Switch block are executed in order. If all of these statements are completed, or if there is no statement after the default tag, the entire Switch statement is done normally. If there is no CASE match and there is no DEFAULT tag, there is no further action that occurs and the Switch statement is done normally. All of the following must be correct, otherwise, compile errors: Each Case constant expression associated with the Switch statement must be the type of Expression that can give Switch. There is no two Case constant expressions associated with the Switch statement have the same value. Only one default tag can be associated with the same SWITCH statement. Example In the following example, we use a FOR loop to iterate four times in the switch statement, and test it with zero to three. For (int Test = 0; test <= 3; test ) {
Switch (TEST) {
Case 1:
System.out.println ("Good");
Break;
Case 2:
System.out.println ("Very Good");
Break;
DEFAULT:
System.out.println ("boring");
Break;
}
} The above code produces the following output: boring
Good
Very good
Boring