This week's book giveaway is in the Design and Architecture forum. We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line! See this thread for details.
hi guys please explain how the answer is correct QUESTION : 6 Consider the following class 1. class Tester { 2. void test (int i) { System.out.println ("int version"); } 3. void test (String s) { System.out.println ("String version"); } 4. 5. public static void main (String args[]) { 6. Tester c = new Tester (); 7. char ch = 'p'; 8. c.test (ch); 9. } 10. } ans print "int version"
it's simple. If u know abt automatic conversion, char field can be assigned to int field (Widening case). so java converts char to int and called appropriate method. Thanks Ashish
Because char is also an integral data type (which does not take -ive integers). When compiler tries to lookup a test method that takes a char, it doesn't find one so it looks for a closest (but eligible!) match, it finds the int version. So it promotes the char to int and calls that method! HTH, Paul. ------------------ http://pages.about.com/jqplus Get Certified, Guaranteed!