Monday, February 23, 2009

method overloading by passing objects




package oops;

public class OLbyPassingObject {

public void m1(String s)
{
System.out.println("String version");
}
public void m1(Object o)
{
System.out.println("Object version");
}
public void m1(double d)
{
System.out.println("double version");
}


public static void main(String a[])
{
OLbyPassingObject s=new OLbyPassingObject();
s.m1("java"); // String version
s.m1(new Object()); // Object version
s.m1(null); // String version
// if Double wrapper version is there we will get compile time error shows abiguous
}

}


0 comments:

Post a Comment