aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green mock exam  3 Q1 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Marcus Green mock exam  3 Q1" Watch "Marcus Green mock exam  3 Q1" New topic
Author

Marcus Green mock exam 3 Q1

kmchow2
Greenhorn

Joined: Aug 29, 2000
Posts: 1
Which of the following are legal statements?
1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;
answer is 1,2,4
how come not only 4?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5781
1) float f=1/3;
Is right because the type of 1/3 is int which can be converted to float without losing precision.
2) int i=1/3;
Strange it may seem, this is right too. The type of expression 1/3 happens to be int here and it gets converted to int i. Though the precision is lost, this is a valid expression.

3) float f=1.01;
You know why this is wrong. Integer literals with a decimal point in them are considered as double, so you need an explicit cast.
4) double d=999d;
Perfectly legal.
So the answers are 1,2,4.

Since there is nothing wrong with this question( and Marcus is ) I am moving this to SCJP forum

Ajith
[This message has been edited by Ajith Kallambella (edited August 29, 2000).]


Open Group Certified Master IT Architect.
Sun Certified Architect(SCEA).
 
IntelliJ Java IDE
 
subject: Marcus Green mock exam 3 Q1
 
Threads others viewed
wrappers
Question on float data type
Data Types
Another Exercise regarding Garbage Collection:
multi dimensional arrays
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture