This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in question" Watch "Doubt in question" New topic

Doubt in question

Patr�cia Oliveira

Joined: Mar 29, 2006
Posts: 8
I saw this question in javablackbelt but I didn't understand the answer. Can someone explain it to me?

You have defined the following methods:

public void print(int val) {

public void print(long val) {

public void print(float val) {

public void print(double val) {

What will be printed after running this code fragment?

1: print('x');
2: print(10);
3: print(1 / 3);

The answer is:

I didn't understand the third print.



Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Whole numbers are considered ints.

The division of an int by an int is an int.

So 1/3 = 0.

So the method that accepts an int is the most specific for 0.
Patr�cia Oliveira

Joined: Mar 29, 2006
Posts: 8
Thank you for reply. Now I understood it.
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
To invoke print(double) version try print(1/3.0)
wood burning stoves
subject: Doubt in question
Similar Threads
Reg. conversion in method calls
Not able to understand the output
Overloaded methods - Boone's Mock Question
conversion and casting
method overloading