► |  | How to Design Classes Languages

1 | Professor J Beginner
2 | Professor J Intermediate
3 | Professor J Intermediate + Access
4 | Professor J Advanced
| Index

▼ | 3 | Professor J Intermediate + Access

3.1 | import
3.2 | class
3.3 | interface
3.4 | Modifiers
3.5 | Field
3.6 | Method
3.7 | Constructor
3.8 | Statement
3.9 | Expression

Version: 4.1.4
top← prev up next →

#### 3.9`` Expression

- Expression Op Expression

  Performs the mathematical or logical operation Op on the value of the two expressions.

- - Expression

- ! Expression

  Performs logical negation on the value of the expression.

- this

  Allows access to the current object. Within a class, fields and methods of the current class can be accessed through this.

- Id (Expression ,...)

  Id names a method of the current class to be called by the current expression. The expressions following Id are evaluated from left to right and passed in to the method as its arguments. The number and types of the arguments must match the method’s declaration. These values replace the argument names in the body of the method, and the result of the body is the result of this expression.

- Expression.Id (Expression ,...)

  The first expression must evaluate to an object value. Id names a method of this object to be called by the current expression. The expressions following Id are evaluated from left to right and passed in to the method as its arguments. The number and types of the arguments must match the method’s declaration. These values replace the argument names in the body of the method, and the result of the body is the result of this expression.

- super.Id (Expression ,...)

  Evaluates the overridden method body using the provided expressions as its arguments.

- Expression.Id

  The first expression must evaluate to an object value. Id names a field of this object, whose value is retrieved by this expression.

- new Id (Expression ,...)

  Evaluates to a new instance (object) of the Id class. The class’s constructor will be run with the given values (evaluated from left to right) as its arguments. The number and types of these values select which constructor is used.

- (Type) Expression

  Evaluates Expression and then confirms that the value matches the specified type. During compilation, the resulting expression has the specified type. If during evaluation, this is not true, an error is raised; otherwise the result of this expression is the result of Expression.

- Expression instanceof Type

  Evaluates Expression and then confirms that the value matches the specified type. Returns true when the type matches and false otherwise.

- check Expression expect Expression

  Compares the resulting values of the two expressions through a deep comparison, including the fields of objects. The resulting value will be a boolean. Neither expression can have type float or double. When test reporting is enabled, results of checks appear in the testing window.

- check Expression expect Expression within Expression

  Compares the resulting values of the first two expressions through a deep comparison. The third value must be numeric. If the resulting values of the compared expressions are numeric, their values must be within the third value of each other. For example, in check a expect b within c, the absolute value of a-b must be less than or equal to c. If the compared expressions evaluate to objects, any numeric fields will be compared with this formula. The resulting value will be a boolean. When test reporting is enabled, results of checks appear in the testing window.

- (Expression)

- Id

  May refer to either a local variable, method parameter, or field of the current class.

- Number

- Character

  Values of type char are ASCII characters enclosed by single quotes such as ’a’ is the character a. They can be used as numbers as well as characters.

- String

  Strings are created through placing text inside of double quotes. For example "I am a string" is a String. A String value is an instance of the class String, which descends from Object, and can also be created with a constructor.

- null

  A value representing an object with no fields or methods. It should be used as a placeholder for uninitialized fields.

- true

- false

top← prev up next →