
Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
> > Hello guys, I am wondering what does following statement mean, please
> > help me understand, thanks you!
[quoted text clipped - 3 lines]
> It assigns a newly created instance of class Second to a variable named
> first, which happens to be of type First.
so what is the different of myVar between the 2 statements, thanks for answering:
Second myVar = new Second();
First myVar = new Second();
Stefan Schulz - 23 Feb 2005 17:35 GMT
> so what is the different of myVar between the 2 statements, thanks for
> answering:
>
> Second myVar = new Second();
> First myVar = new Second();
The first declaration declares a variable of type First, and assigns it a
reference to a newly created object of type Second. The second statement
declares a variable of type second, and assigns it a reference to a newly
allocated object of type Second.

Signature
In pioneer days they used oxen for heavy pulling, and when one ox
couldn't budge a log, they didn't try to grow a larger ox. We shouldn't
be trying for bigger computers, but for more systems of computers.
--- Rear Admiral Grace Murray Hopper
Oscar kind - 23 Feb 2005 17:52 GMT
> so what is the different of myVar between the 2 statements, thanks for answering:
[renamed variables]
> Second myVar1 = new Second();
> First myVar2 = new Second();
myVar1 is an instance of Second, but your code sees it as an instance of
First (it's superclass), as that is the type of the reference. You can
therefore only use it as an instance of First, unless you cast it to a
Second.
myVar2 is also an instance of Second, and your code sees it as such. You
can therefore use it as an instance of Second.

Signature
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
Big Jim - 23 Feb 2005 22:34 GMT
It might help your understanding if you look up some introductory
information on inheritance and polymorphism, these subjects are the basis of
your question but are a bit too large to go into here without a basic idea
to start from.
>> > Hello guys, I am wondering what does following statement mean, please
>> > help me understand, thanks you!
[quoted text clipped - 9 lines]
> Second myVar = new Second();
> First myVar = new Second();
dar7yl - 28 Feb 2005 05:38 GMT
>> > Hello guys, I am wondering what does following statement mean, please
>> > help me understand, thanks you!
[quoted text clipped - 9 lines]
> Second myVar = new Second();
> First myVar = new Second();
For those purists here, you should be aware that
these statements are in error, as you are redeclaring
myVar and would generate a compiler error.
regards,
Dar7yl