executable statements 1. def. executable statements are instructions to the computer to perform...

6
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment statements 3. What are two classifications of methods? (void and value returning) 4. Syntax for calling a method: objectName.methodName()

Upload: leon-barnett

Post on 05-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

Executable Statements

1. Def. Executable statements are instructions to the computer to perform specific tasks.

2. Two examples:

method calls and assignment statements

3. What are two classifications of methods?(void and value returning)

4. Syntax for calling a method:

objectName.methodName()

Page 2: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

5. Note: a method called from within the class in which it is defined (or a subclass) can be made without the objectName and without a dot.

6. Void method calls are statements themselves, but value returning methods must be in assignment statements.

aPiece.readSqMeter();

objectName methodName no arguments

val = getDouble();

Page 3: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

7. A value returning method must have a return statement somewhere in its block ( usually the last statement).

8. A return statement consists of the reserved word

return followed by a variable or expression.

9. Methods may (or may not) have arguments.

Arguments are variable names separated by commas.

10. Note: the position, type, and no. of arguments in the method call must match those in the method heading.

Remember: no types are stated in the method call.

See p.81

Page 4: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

11. Def. assignment statement an instruction that stores a value (or result of an expression) in a variable.

The assignment operator is: =

12. ex. char ch = ‘z’;

ans = 3.5 + cost; //typing done previously

d = getDouble( );

13. Arithmetic operators permitted in expressions in order of precedence:

- (unary minus)

*, /, % (left associative for operators of same level)

+ , -

Page 5: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

14. Expressions with 2 integer operands result in an int.

15. / results in the quotient % results in the remainder

ex. int c = 5 / 2 results with 2 stored in c

int d = 5 % 2 results with 1 stored in d16. Expressions with 1 integer operand and 1 double operand results in a double

unless typecasting is used.

17. Def type casting creates a value of one type from a variable or expression of another type.

Page 6: Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment

Ex. int m = 5, n = 2, c;

double x = 3.8

c = x + m / n

3.8 + 5 / 2

3.8 + 2

error !!

c = (int) x + m / n

3 + 5 / 2

3 + 2

c = 5

See p.92 Do p.95 # 1 - 4