This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor invocation? 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 "Constructor invocation?" Watch "Constructor invocation?" New topic
Author

Constructor invocation?

Ramana Uppala
Greenhorn

Joined: Jan 04, 2005
Posts: 16
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

Joined: Aug 23, 2004
Posts: 57
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

Joined: Oct 11, 2004
Posts: 3830
Because by default any un-fractional ( non-float ) number is int .
Ramana Uppala
Greenhorn

Joined: Jan 04, 2005
Posts: 16
Thanks
 
GeeCON Prague 2014
 
subject: Constructor invocation?