Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class, superclass, subclass problemo

 
Timothy Onggowasito
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
John de Michele
Rancher
Posts: 600
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's more likely you didn't delete the old class file.
 
Timothy Onggowasito
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic