• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Casting & Conversion !

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have not seen any Tips or discussion on Casting /conversion,specially for Object references. Can somebody give some tips.
Thanks in advance.
Nirmala
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Casting I hope you mean type casting
Look into the code below
Class iTest{
public static void main(String args[]){
float f;
f=9/2;
System.out.println(f);
}
}
Answer for this will be 4 instead of 4.5 reason is integer windup. Replace the line f=9/2 by f=(float)9/2 and you get the correct answer ie 4.5
I hope this helps you
======================
Object o = new String("Hello")
String s = o /*This line will generate and error but if you do
like String s = (String)o ...... */
I hope you got what you are looking for

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jafarli that means any calculation that take place will the upcasted or downcasted to int.
 
reply
    Bookmark Topic Watch Topic
  • New Topic