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.

3 comments:

Ponnarasi Kothandaraman said...

Hi,
Techincal :P Enaku romba thooram ;)?
Bytheway there is a tag in my blog. I felt you might be interested 2 write the tag :)

Pls have a look and feel free 2 ignore if you are not interested to write :)

Raghs said...

@Ponnarasi,
Thanks for visiting and commenting! Nice to hear that you are away from the technical which we can't ;-(!
lemme have a look and try!

Take Care.
But you can visit other blogs of mine.. he he he..

Pankaj said...

Kewl Explanation. !!

About Me

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