Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the meaning of "Primitive widening uses the smallest method argument possible"???

 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone elaborate this sentence with some explanation???
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider following snippet of code


public void guru(long a , long b){}

public void guru(int a , int b) {}


Now consider following method call

byte a=9;
byte b = 8;
guru(a,b);

here we are calling guru method with 2 bytes. now which one will be invoked ? the answer lies in your question. the method with the smallest argument than the parameters are selected. in this case guru(int a, int b) will be selected.
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic