This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes class, superclass, subclass problemo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "class, superclass, subclass problemo" Watch "class, superclass, subclass problemo" New topic
Author

class, superclass, subclass problemo

Timothy Onggowasito
Greenhorn

Joined: Apr 16, 2010
Posts: 11
Hello ranchers,
I'm trying to learn Java from HeadFirst Java book by Kathy & Bert Chapter 9, page 255. I've struggle through all the previous chapter but manage to understand the concept.
But one thing that I'm stuck on is this code on page 255:



the code above is right, I understand it but when I played around with it and change the class name and it's constructor to Hippau like :


It still works!
I don't get it when I create the new object Hippo like:
Hippo h = new Hippo ("Buffy");
what class does the object Hippo refer to? I've just changed the class Hippo to Hippao.
I'm so confused.

Maybe I didn't get the concept of object oriented programming yet....

Thanks in Advance
Timothy. O


Apparently, what you don't know can hurt you...
Tim Ong
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Timothy:

The Java compiler is rather simple minded. If you change the name of a class, it forgets the old name, and expects the new name to be present.

John.
Timothy Onggowasito
Greenhorn

Joined: Apr 16, 2010
Posts: 11
Hmm... Now I'm twice as confused.

maybe this question will clear things up.

Does the object Hippo still refers to the class Hippau (previously named Hippo)?
if so, then doesn't that mean that the compiler remembers the old name in which it was named Hippo?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's more likely you didn't delete the old class file.
Timothy Onggowasito
Greenhorn

Joined: Apr 16, 2010
Posts: 11
Ahh that clears things up, I didn't know the compiler creates a new class file anytime I change it's name
I'm so ashamed.

Thanks for the help.
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
Timothy Onggowasito wrote:........ I didn't know the compiler creates a new class file anytime I change it's name ...

Timothy,
Compiler create one .class file for one concrete class. (irrespectible whether they all are written in single .java file). That's why you got class Hippo and Hippau. It is always advisable to do clean build after modification.
 
GeeCON Prague 2014
 
subject: class, superclass, subclass problemo