Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 TypeCasting and Promotion?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hq78




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: 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:

code:
Object foo = new Integer(5);


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.

code:
Integer bar = (Integer)foo;


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.
rizzix




PostPosted: Thu Jan 06, 2005 9:38 pm   Post subject: (No 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
wtd




PostPosted: Thu Jan 06, 2005 9:41 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: