Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

August 24, 2009

A very good interview question (OverridingTest ) --> Static Polymorphism

Q: What would be the output of the following program ?
public class OverridingTest {



//~ Methods --------------------------------------------------------------------------------------------------------



public static void abc(Object str) {

System.out.println("Object");

}



public static void abc(String str) {

System.out.println("String");

}



public static void main(String[] args) {



// Example of Static polymorphism

abc(null);

abc((Object) null);



String[] str = { null, null, null, null };



for (String st : str) {

abc(st);

}

}

}

Ans : String

Reason : http://www.javafaq.nu/java-article383.html

No comments: