Bert Porter

Greenhorn
+ Follow
since Feb 10, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bert Porter

What's your favorite introduction to Android? Where do you send people to kick them into gear and get them with the program?
13 years ago
"Oh, very excited to see their mother tongue"
Hi, Peter. Thanks for coming to talk about your book. It looks like it could be fascinating. Were there any things that really surprised you in the process of interviewing all these star coders? Any unexpected themes reveal themselves?

Thanks,
Bert
14 years ago
Yes. I'm following the formula for posting a typo for the errata page.
pg. 281, Exercise 7 in the Self Test Answers, line 12, has "NOTRUMP.getBidValue" which won't compile. Where the problem is originally given on pg. 272, we have the correct "NOTRUMP.getValue".
"ZooKeeper" topic turns out to be an instance of shadowing.
OK, I read on into chapter 3, and when I got to shadowing, I saw that that's what we have here.
I think a Zebra object must actually have two instance variables called 'name' - and which one is visible depends on whether your reference variable thinks it's looking at a Zebra or a Mammal. I'd call this a pathogenic subclass. In fact, I'd advocate making it illegal to do this.
Himalay says, "Remember, Superclass reference variable(In this caseL m) dont refer to instance variables of subclass." I don't get this. Doesn't a reference variable refer to an object, i.e. an instance? Doesn't an instance variable belong to an instance? It isn't a static variable. So, m refers to an object on the heap. The dot operator goes to that object, right? The object has an instance variable called 'name'. The object (not the class) has a value for that instance variable.
m and z2 both refer to the same object. But m.name is different from z2.name. I thought that m was just a type (Mammal) and a pointer to an object. So m.name would mean, go to the object which m refers to, and retrieve the value of name from that object. Apparently, I am wrong. Somehow, m maintains its own value of the instance variable 'name', independent of the object it refers to. I think that's kooky.
I'm having trouble with question 13 in the Self Test for Ch. 2 of K&B SCJP6.
Given:

What is the result?
The result is "furry bray" but I don't see why it wouldn't be "stripes bray". m refers to a Zebra. I tried the following to sort it out, but it hasn't exposed the key to me.