Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment."— Presentation transcript:

1

2 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()

3 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(); objectNamemethodNameno arguments val = getDouble();

4 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

5 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) +, -

6 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 d 16. 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.

7 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


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

Similar presentations


Ads by Google