Computer Science Canada TypeCasting and Promotion? |
Author: | hq78 [ Thu Jan 06, 2005 9:02 pm ] |
Post subject: | TypeCasting and Promotion? |
Can someone tell me what Typecasting and Promotion are in Ready To Program Java IDE by holtsoftware? |
Author: | wtd [ Thu Jan 06, 2005 9:11 pm ] | ||||
Post subject: | Re: TypeCasting and Promotion? | ||||
hq78 wrote: Can someone tell me what Typecasting and Promotion are in Ready To Program Java IDE by holtsoftware?
Casting is aking an object of one class and forcing the environment to regard it as an object of another class. Let's ignore primitives (int, float, boolean, etc) for now. Every object, due to inheritance, is an "Object", so we can do something like:
However, when we do this, we can only treat the variable "foo" as a relatively limited object of type Object. But, we can use a cast to "turn" that object back into an Integer.
We're "promoting" foo to an Integer from an Object. Of course, you can't just cast foo to anything... if you try to, an exception will occur. |
Author: | rizzix [ Thu Jan 06, 2005 9:38 pm ] |
Post subject: | |
hmm wtd.. well oop speaking you could be right.. but nywys promotions do have another meaning (in java). so refer to this post for more info: http://www.compsci.ca/v2/viewtopic.php?p=16822#16822 |
Author: | wtd [ Thu Jan 06, 2005 9:41 pm ] |
Post subject: | |
rizzix wrote: hmm wtd.. well oop speaking you could be right.. but nywys promotions do have another meaning (in java).
refer to this post for more info: http://www.compsci.ca/v2/viewtopic.php?p=16822#16822 Ah. You're talking about primitive promotion. Darn Java for having both primitive and object types. |