• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

importance of parameter

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Q48
{
static int x = 9;
static int y = 'V';

public static void processInt(int i)
{
System.out.println("process-1");
i = 18;
process(y);
}

public static void process(long l)
{
System.out.println("process-2");
l = 27;
}

public static void process(short s)
{
System.out.println("process-3");
s = 36;
}

public static void main(String[] args)
{
processInt(x);
System.out.println(x);
System.out.println(y);
System.out.println((char)y);
}
}
why process(long l) called instead of process(int i) when passing integer parameters
thanks in advance
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Helo!
Int does not fit in short version thus next wider version, long, is chosen since int version is missing.
------------------
Antti Barck
It Solutions Consultant, NSD Oy
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Payal,
I am confused about your question. You have only two methods named process one takes a long and the other takes a short.
The long method is called because the compiler will automatically widen an int into a long. The compiler will never narrow automatically without complaining loudly.
Regards,
Manfred.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manfred Leonhardt:
Hi Payal,
I am confused about your question. You have only two methods named process one takes a long and the other takes a short.
The long method is called because the compiler will automatically widen an int into a long. The compiler will never narrow automatically without complaining loudly.
Regards,
Manfred.


I almost hear me saying the same - is my english that BAD!!!

------------------
Antti Barck
It Solutions Consultant, NSD Oy
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all:
I think Payal wanted us to think on a different line.In the original version of the problem you are correct to say that process(long) is getting called since the *int y* that is being passed to the process(int) within the processInt(int) method doesnot fit into the process(short) format.
Let us modify the code to the following and then discuss the issue :


Which overloaded process() method would be called and why?
Looking forward for the discussion on this.
-- Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited July 26, 2001).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi desai!
So you put the in version of process there which was originally not there.
------------------
Antti Barck
It Solutions Consultant, NSD Oy
 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for your prompt reply in my every post-
Yes sandeep is correct I want to ask this issue and I even written the same code with some modification in other post --> refrencing problem.
thanks in advance
payal
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't this method called........
public static void process(int i) {
System.out.println("process-4");
.........
}

Somehow these seems obvious to me.Am I missing something.....
Rajani
Which overloaded process() method would be called and why?
Looking forward for the discussion on this.
-- Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
[This message has been edited by Desai Sandeep (edited July 26, 2001).][/B]
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I had replied to a post by Payal in sufficient depth, which eventually went on to discuss the ambiguity errors while compilation.
That should answer why process(int i), is being called in this case.
Let me know if you still have problems.
Hope this helps,
Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic