aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in question" Watch "Doubt in question" New topic
Author

Doubt in question

Patr�cia Oliveira
Greenhorn

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) {
System.out.println("int");
}

public void print(long val) {
System.out.println("long");
}

public void print(float val) {
System.out.println("float");
}

public void print(double val) {
System.out.println("double");
}

What will be printed after running this code fragment?

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

The answer is:
int
int
int

I didn't understand the third print.

Thanks,

Pati


Pati
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
Greenhorn

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in question