{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

08 - CS133 Developing Programming Principles Lecture 8 All...

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

View Full Document Right Arrow Icon
1 CS133: Developing Programming Principles Lecture 8 All about references: the memory model, passing parameters, the null reference 2 CS133 Course Notes Lecture 8, Slide 2 Rectangle Class A Rectangle has a height and a width, and the following methods: public Rectangle(double h, double w) public void setWidth(double newWidth) public void setHeight(double newHeight) public double getWidth() public double getHeight() public double calcArea() public double calcPerimeter() public boolean equals(Rectangle other) public String toString()
Background image of page 1

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

View Full Document Right Arrow Icon
3 CS133 Course Notes Lecture 8, Slide 3 Rectangle : equals() method // pre: other != null // post: returns true if this and // other represent identical // rectangles public boolean equals(Rectangle other) { return (this.height == other.height) && (this.width == other.width); } 4 CS133 Course Notes Lecture 8, Slide 4 How primitive types are stored Java code: int salary = 100; char initial = 'T'; • Memory: salary initial 100 'T'
Background image of page 2
5 CS133 Course Notes Lecture 8, Slide 5 The CS241 View Java code: int salary = 100; char initial = 'T'; • Memory: 2004 'T' initial 2000 100 salary Address 6 CS133 Course Notes Lecture 8, Slide 6 References A reference is the memory address where an object is stored. Recall that we typically do not compare objects using == or assign values to them using =. • Why?
Background image of page 3

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

View Full Document Right Arrow Icon
7 CS133 Course Notes Lecture 8, Slide 7 Picture Java code: int salary = 100; char initial = 'T'; Rectangle rec1 = new Rectangle (3.0, 2.5); Memory: salary initial rec1 width height 100 'T' 2.5 3.0 8 CS133 Course Notes Lecture 8, Slide 8 Picture explained Notice the variable rec1 doesn’t have the value
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}