File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes valid and invalid declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "valid and invalid declarations" Watch "valid and invalid declarations" New topic

valid and invalid declarations

abhay patil

Joined: Apr 26, 2007
Posts: 9
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

Joined: Mar 27, 2004
Posts: 401

This is a Widening Primitive Conversion. int types can be implicitly converted to float, double and long. Please, check the following articles:
[ May 02, 2007: Message edited by: Leandro Melo ]

Leandro Melo
SCJP 1.4, SCWCD 1.4
subject: valid and invalid declarations
It's not a secret anymore!