Chapter2_3-Operators

A variables are a variables are a allocated in memory

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n of the expression is stored in the space memory allocated for variable at the left side. A. Variables are A. Variables are A. allocated in memory. allocated in memory. first sum A A int first, second, sum; first = 234; second = 87; Sum = first + second Code B B 11 ??? ??? ??? ??? second B. Values are B. Values are B. assigned to variables. assigned to variables. first 234 234 sum 87 87 321 321 second State of Memory Page 14 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Updating Data A. The variable A. The variable A. is allocated in is allocated in memory. memory. number ??? ??? B. The value 237 B. The value 237 B. is assigned to is assigned to number. number number. int number; number = 237; number = 35; number A A B B C C C. The value 35 C. The value 35 C. overwrites the overwrites the previous value 237. previous value 237. number Code Page 15 237 35 State of Memory Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Example: Sum of two integer public class Sum { // main method public static void main( String args ){ int a, b, sum; a = 20; b = 10; sum = a + b; System.out.println(a + ” + ” + b + “ = “ + sum); } // end main } // end class Sum Page 16 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Arithmetic/Assignment Operators Java allows combining arithmetic and assignment operators into a single operator: Addition/assignment Subtraction/assignment Multip...
View Full Document

This document was uploaded on 03/03/2014.

Ask a homework question - tutors are online