wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Primitive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Primitive" Watch "Primitive" New topic
Author

Primitive

Angie Jin
Greenhorn

Joined: Jan 25, 2001
Posts: 4
Hi. This is my first time here. It is really great!! It has solved a lot of questions of mine.Now I have one more question. Please help me.
I am always confused about the assignments between primitives.I don't know when the casting is required.Here is my understanding and my questions. Please correct and answer me.
double = int Yes
int = double No
float = double No
double = float ??
int = long No
long = int Yes
How about the case in method call? e.g. Method(int x, int y) can I call it like Method(double, double)? How about the reverse?
Thank you very much.
Marine
Greenhorn

Joined: Jan 25, 2001
Posts: 25
double = int Yes
int = double No
float = double No
double = float ??
int = long No
long = int Yes
Ok when you are doing assignment think in this terms. The smaller type will always fit into a larger one right ?
double = float yes you can.
also remember if you don't specify float f = 10.2f with an f it will be treated as a double literal.
Now about method call i didn't understand something. Do you mean if your method is designed to accept int values and you send it a double value what would happen ? It's a mistake to do this. And will result in an error. But if you pass to that method a short or a char they are going to be promoted to int values. I hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Primitive
 
Similar Threads
method arguments ?
method params!
Overloading
int to float conversion !
Doubt in implicit/explicit conversions