This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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
I agree. Here's the link:
subject: valid and invalid declarations
It's not a secret anymore!