ClassA hi = new ClassB()
What does it mean when you initialize an object of one type, and then declare it as another type? I don't get what this does or what the purpose is.As an exampleClassA hi = new ClassB();
[208 byte] By [
Lava_Javaa] at [2007-11-27 10:07:43]

Google for "Abstraction in Java".
> Google for "Abstraction in Java".Followed closely by "polymorphism"
also check inheritance in java http://www.google.com/search?q=inheritance+in+java&sourceid=navclient-ff&ie=UTF-8&rlz=1B3GGGL_enUS225US225&safe=active
I'm somehwat familiar with all these terms. I'm just not familiar with the concept of declaring an object one type and initializing it as another. And while GOogling these terms, I couldn't find any examples specific to what I'm talking about.
Example:Set < Foo > x = new HashSet < Foo > ();The important thing is that x is a set. That it's implemented by hashing is an implementation detail.
> I'm somehwat familiar with all these terms. I'm just
> not familiar with the concept of declaring an object
> one type and initializing it as another.
Mammal furry = new Moggy("Tibbles");
...
furry = new Mouse("Gerald");
...
The types have to be compatible. If furry was declared as having type Moggy we wouldn't be allowed to assign a Mouse instance to it later on.
> ClassA hi = new ClassB();
Car c = new Porsche();
On the left side we're saying, "c is the spot where a car is parked."
On the right side we're saying, "the particular car that's parked in slot c is a Porsche."
"Hand me a screwdriver."
"Here's a Crafstsman phillips-head."
"Put some fruit in this bag."
"Here's an apple."
I see this devolving into a tortured analogy competition :-)
Not really.I was just trying to relate the concept to more real-world-ish, code-free examples.
> I see this devolving into a tortured analogy competition :-)Frankly, I'd prefer he keep is fruit in his own bag, thank you.~
> > I see this devolving into a tortured analogy> competition :-)> > Frankly, I'd prefer he keep is fruit in his own bag,> thank you.Oh, sure, you say that now.
> Oh, sure, you say that now.Well, yeah. You've been bagging fruit all over town; you can't expect me to act like nothing's changed.~
> > Oh, sure, you say that now.> > Well, yeah. You've been bagging fruit all over town;> you can't expect me to act like nothing's changed.> > ~I'm on a mission from God.
> > I'm on a mission from God.I don't like your God. Your god scares me.