Java Puzzle – Method Overloading

Program -

public class OverloadingPuzzle {
    public void display(Object obj){
        System.out.println("Object version");
    }

    public void display(String str){
        System.out.println("String Version");
    }

    public static void main(String[] args){
        OverloadingPuzzle obj = new OverloadingPuzzle();
        obj.display(null);
    }
}

I was expecting that this program prints “Object Version” but ….

Output

String Version

Why ? – Searching ….

Comments

Popular posts from this blog

Composite Design Pattern by example

State Design Pattern by Example

Eclipse command framework core expression: Property tester