Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

confusion code

Thread view: 
gk - 14 Sep 2006 14:57 GMT
public class PowerSupply
 {
    public PowerSupply(String voltage){
        System.out.println ("PowerSupply(String) executed");
    }
    public PowerSupply(Object voltage){
        System.out.println ("PowerSupply(Object) executed");
    }
    public PowerSupply(){
        System.out.println ("No argument constructor execute");
    }
    public static void main(String[] args) {
        PowerSupply ps = new PowerSupply(null);
    }
 }

what would be the output ?

output:  PowerSupply(String) executed\

i dont know  why  the JVM is choosing the first constructor for
argument null .

please  explain...how this output coming ?
Oliver Wong - 14 Sep 2006 15:23 GMT
> public class PowerSupply
>  {
[quoted text clipped - 20 lines]
>
> please  explain...how this output coming ?

   JLS states that the when selecting between overloaded methods, the "most
specific" method will always be chosen. They then go into great lengths
defining "most specific". Informally, any parameter that could be passed
into the first constructor (String voltage) could also be passed into the
second constructor (Object voltage), but not the other way around, so the
first constructor is "more specific" than the second one.

   - Oliver
gk - 14 Sep 2006 15:30 GMT
thanks ...this helps

> > public class PowerSupply
> >  {
[quoted text clipped - 29 lines]
>
>     - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.