Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor invocation?

 
Ramana Uppala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the below program why not byte or short constructor not called.


public class Test2 {
Test2(byte i)
{
System.out.println("in byte constructor");
}Test2(short i)
{
System.out.println("in short constructor");
}Test2(int i)
{
System.out.println("in int constructor");
}Test2(long i){

System.out.println("in long constructor");
}
Test2(){}
public static void main(String args[]){
new Test2(2);
}
}
 
Nikhilesh Fonseca
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you tried type casting the parameter (byte),(short),1l the correct construcotr is called. Maybe as we have deafult value of 1.1 as a double the
default value of non floating point nos is int ....I dunno really
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because by default any un-fractional ( non-float ) number is int .
 
Ramana Uppala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic