lec20Feb1808

lec20Feb1808 - Lecture 20 Assignment Revisited • An...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: Lecture 20 February 18, 2008 Assignment Revisited • An assignment takes a copy of a value and stores it in a variable int num = 100; int addOne = num + 1; • For object reference, assignment copies the memory location Point firstPoint = new Point() Point secondPoint = firstPoint; public static int add(int firstNum, int secondNum) … int mySalary = 1000; int yourSalary = 800; int total = add(mySalary, yourSalary) Actual Parameter Formal Parameter Parameter Passing • Parameters in a Java method are passed by value – i.e. a copy of the actual parameter (the value passed in) is stored into the formal parameter (in the method header) – Changing the local copy does not affect the original – Not true for objects! • When an object is passed to a method: – The actual parameter and the formal parameter become aliases of each other – The value of the variable is passed by value and the formal parameter receives a copy of this value • This means that both variables refer to the same object •...
View Full Document

This note was uploaded on 04/14/2008 for the course COMP 202 taught by Professor Verbrugge during the Winter '07 term at McGill.

Page1 / 16

lec20Feb1808 - Lecture 20 Assignment Revisited • An...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online