*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor invocation?
 
Similar Threads
Constructor Q
Constructors
Method invocation promotion in java
Casting Difference of Float.POSITIVE_INFINITY
int -> float -> int and loss of precision