File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which method will be called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "which method will be called " Watch "which method will be called " New topic

which method will be called

aruna makhija

Joined: Dec 07, 2000
Posts: 17
Hi friends,
This is my first post! I was unable to find a good description of this topic in RH and Bill Brodgen's Exam Cram. Will the JLS be helpful ? Do you think we should study the JLS real well before taking the exam ?
Please tell me What is the result of executing the following code:
class Test {
public static void main(String[] args) {
Test t = new Test();
t.test(1.0, 2L, 3);
void test(double a, double b, short c) {
void test(float a, byte b, byte c) {
void test(double a, double b, double c) {
void test(int a, long b, int c) {
void test(long a, long b, long c) {
Ragini Kelkar

Joined: Oct 19, 2000
Posts: 9
The test method is called with(1.0,2L,3) which is
Since there is no test method that exactly matches this it will select the one that will promote the parameters passed to the required values.
Hence it will call test(double,double,double)
Hence it will promote long and int to double.
It will print 3.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
You might want to read JLS§5.3 Method Invocation Conversion.
It doesn't hurt to through the JLS; it has a number of code examples that are worth working through.
Hope that helps.
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: which method will be called
It's not a secret anymore!