This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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
Consider Paul's rocket mass heater.
subject: valid and invalid declarations