Presentation is loading. Please wait.

Presentation is loading. Please wait.

©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.

Similar presentations


Presentation on theme: "©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting."— Presentation transcript:

1 ©2004 Brooks/Cole Chapter 10 More on Classes

2 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting one variable equal to another copies the value of the variable on the right into the variable on the left. With objects, what is copied is the address of the object –there is only one object

3 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Two Book objects After Assignment book2 = book1

4 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Making Copies of Objects To copy an object you need a method –Copy constructor public Date( Date original) –A method public void setEqual( Date d) –Override the clone method from the Object class

5 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Scope Re-visited Variables declared inside a method are local to the method Method parameters are local to the method Variables declared in the body of a class (outside on any method) are visible in all the methods of the class

6 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 An Example of Scopes

7 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Static Members Variables declared with the static modifier are shared by all objects that belong to the class Methods declared with a static modifier do not have any instance data associated with them

8 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sharing the Static Data Member taxRate

9 Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Storage of Two Date Objects in Memory


Download ppt "©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting."

Similar presentations


Ads by Google