Class Notes (1,100,000)
CA (620,000)
U of C (8,000)
CPSC (100)
Lecture 13

CPSC 233 Lecture Notes - Lecture 13: Class Variable


Department
Computer Science
Course Code
CPSC 233
Professor
Leonard Manzara
Lecture
13

This preview shows half of the first page. to view the full 3 pages of the document.
CPSC 233 - 8 Feb Mon
The “this” Keyword
As seen before, this() can be used to invoke other constructors
this() is also used for object self references
(E.g.)
public class Point{
private double x,y;
public Point(double x, double y){
this.x = x; self references are necessary to distinguish
this.y = y; instance variables from parameters
}
}
this() can be used by an object to send a message to itself
(E.g.)
public class Point {
. . .
public void setX(double xVal) {
x = xVal;
}
public void setX(double xVal) {
x = xVal;
}
public void set(double xVal, double yVal) {
this.setX(xVal);
this.setY(yVal);
}
}
this() can be used to send a self reference to another object
(E.g.)
. . .
List list = new List();
list.add(this);
. . .
You're Reading a Preview

Unlock to view full version