discussing some technical aspects covering tools, frameworks, technologies etc (the areas where i m involved and getting experienced) - feel free to discuss!

Tuesday, January 16, 2007

Java #Q1: What would be the output?

public class Test
{
public void method1(Object o)
{
System.out.print("object");
}
public void method1(String s)
{
System.out.print("string");
}
public static void main(String[] args)
{
Test t = new Test();
t.method1(null);
}
}


When running the program, the output would be
(a) object
(b) string
(c) objectstring
(d) stringobject


Answer:
(b) string

Explanation:
It is the hierarchy of objects being searched for a match, which is quite similar to the exception objects of catch blocks. The search process is done in the bottom-up manner wherein the object of class of least node is searched first and its continued upwards to the super/parent classes till the end is reached.

About Me

ஏதோ பிறந்தோம், ஏதோ வாழ்ந்தோம் என்றிருப்பதல்ல வாழ்க்கை! எப்படி வாழ்ந்தோம் என்பதும் ஒரு அங்கம். வாழக் கிடைத்த வாழ்க்கையில், ஒரு சிலருக்காவது வசந்தத்தின் முகவரியை அறிமுகம் செய்தோமேயானால் அதுவே வசீகரத்தின் வனப்பைக் கூட்டும்!