Casting with Object Refs
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   JAMES_WEST
Posted On:   Tuesday, February 3, 2004 08:25 PM

Guys

I am here again! Need some help as usual.

Why are casts needed with object reference variables?

how are casts used with object references?

Example code to illustrate the above would be appreciated?

Re: Casting with Object Refs

Posted By:   Anjan_Bacchu  
Posted On:   Tuesday, February 3, 2004 10:00 PM

Hi There,



casting is required only for strongly typed languages like Java. They are not required for say, something like javascript, python, perl, etc.



You can download an excellent book at
http://64.78.49.204/ which will give detailed explanations on how casting is needed.



void bar() {

Object a = new String();

foo(A);

.

.

.
}



void foo(Object a){

String b = (String) a; // Example of casting an Object to String

.

.

.

}
About | Sitemap | Contact