• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valid and invalid declarations

 
abhay patil
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following are not a valid declarations?
A1 float f = 1;
A2 float f = 1.2f;
A3 float f = 1.2;
A4 float f = (float)1.2;
In this case float f =1 is a valid declaration. Can any one help me why this declaraion is a valid declaration.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

This is a Widening Primitive Conversion. int types can be implicitly converted to float, double and long. Please, check the following articles:

http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#184206
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25214
[ May 02, 2007: Message edited by: Leandro Melo ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic