Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scjp question required

 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class test1 {
void c(int i){
System.out.println("int");
}
void c(String s){
System.out.println("String");
}
public static void main(String[] args) {
test1 t=new test1();
char ch='p';
t.c(ch);
}
}
Why the result is :
int ??
Thanks!!
 
Gil Li
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

here the "int" will be printed because the ascii value will be passed. U can print the value i to know it ..
 
natarajan raman
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,

This prints "int" because the when t.c(ch) is called it looks for the function with argument as Character.

char is essentially the only unsigned integral type. So when it calls invokes the first function with integer argument.

Hope this helps.
 
VINCE CARTER
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic