[3626] in java-interest
What's the deal with the variable *this*?
daemon@ATHENA.MIT.EDU (Michael Mehrle)
Sun Nov 19 18:04:11 1995
Date: Fri, 17 Nov 1995 13:07:14 -0700
To: java-interest@java.Eng.Sun.COM
From: michael@w3media.com (Michael Mehrle)
Here's one question I originally e-mailed to John December (author of
"Presenting Java"). If anyone else could answer this question, it would be
_greatly_ appreciated!
Congratulations to your book, it's a whole lot better than Java! (by Tim
Ritchey). I'm a bloody beginner and your book helped a lot to master the
"basicbasics" of Java. Hope that makes you feel better.;)
I've got a question though: Here is a copy of your Segment class (please
check out my comments, they're explained below):
class Segment {
private String thePlace = "Unknown";
private int segmentNumber;
Segment (int number) {
segmentNumber = number; // *here's the bad boy, shouldn't it say:
// this.segmentNumber = number; ?
}
Segment(int number, String aPlace) {
this(number);
thePlace = aPlace; // also here: this.thePlace = aPlace; ?
}
public void header() {
System.out.println("Segment #" + segmentNumber + " " + thePlace);
}
public void action() { }
public void cut() {
System.out.println("---------------");
}
}
Saw the remarks above? So this should apply to the subclass also then:
class Dialogue extends Segment {
private Person personA;
private Person personB;
Dialogue (int number) {
super(number);
}
Dialogue(int number, String aPlace) {
super(number, aPlace);
}
Dialogue (int number, String aPlace,
String actor1Name, String actor2Name) {
this(number, aPlace);
personA = new Person(actor1Name); // this.personA = new
Person(actor1Name);?
personB = new Person(actor2Name); // this.personA = new
Person(actor1Name);?
}
public void action() {
greetings();
talk();
wrapup();
}
.... more methods ...
}
}
You might wonder *where* I took that from. The URL is:
http://java.sun.com/whitePaper/java-whitepaper-5.html#HEADING5-23
Are this specifications just make-up and optional? According to the
description these variables are used to clarify which variable one is
referring to. In
the Segment method, *this.segmentNumber* would mean the *segmentNumber
instance variable* of this object, rather than the SegmentNumber parameter
to the Segment method.
Please let me know if I'm totally off track, or if I was right.
Your reader,
Michael Mehrle
--
P.S. I will also post this message to comp.lang.java, so that everybody
can enjoy your reply (no I don't mean that maliciously!)
||||
o o
____________OOOo___<>___oOOO_______________
http://www.w3media.com/w3media
michael@w3media.com
Tel. 310.441.9599
Fax 310.441.5919
"One man's mundane and desperate existence
is someone else's Technicolor."
-Strange Days-
||||
o o
____________OOOo___<>___oOOO_______________
http://www.w3media.com/w3media
michael@w3media.com
Tel. 310.441.9599
Fax 310.441.5919
"One man's mundane and desperate existence
is someone else's Technicolor."
-Strange Days-
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com
||||
o o
____________OOOo___<>___oOOO_______________
http://www.w3media.com/w3media
michael@w3media.com
Tel. 310.441.9599
Fax 310.441.5919
"One man's mundane and desperate existence
is someone else's Technicolor."
-Strange Days-
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com