Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!

Kefe Abalov

Greenhorn
+ Follow
since Jul 15, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kefe Abalov

going up from the hierarchy, a String object is found first than Object, which is the parent for all classes. that's the reason public void myMethod(String s) is invoked.


Andres Gonzalez thanks for ur explanation though i didn't ask clearly
and if i rewrite the code and replace the "Object" with "StringBuffer",just like this below
public class test
{
public void myMethod(StringBuffer o)
{
System.out.println("My Object");
}
public void myMethod(String s)
{
System.out.println("My String");
}
public static void main(String args[])
{
test t = new test();
t.myMethod(null);
}
}
it won't compile since the StringBuffer and String are in the same hierarchy and the compiler can't decide which method should invoke.
[ August 07, 2003: Message edited by: Kefe Abalov ]
public class test
{
public void myMethod(Object o)
{
System.out.println("My Object");
}

public void myMethod(String s)
{
System.out.println("My String");
}
public static void main(String args[])
{
test t = new test();
t.myMethod(null);
}
}
r there any other class accept "null" ?
[ August 06, 2003: Message edited by: Kefe Abalov ]
Given:
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.println(�x = � + x);
5. }
6. }
What is the result?
A. x = 0
B. x = 42
C. Compilation fails because of an error in line 2 of class Test2.
D. Compilation fails because of an error in line 3 of class Test1.
E. Compilation fails because of an error in line 4 of class Test2.
Answer: C
why not E
i think E is correct
given:
12.void start(){
13.A a = new a();
14.B b = new b();
15.a.s(b);
16.b=null;
17.a=null;
18.System.out.println("start is over");
}
when the object B ,created in the line 14,eligible for garbage collection?
A.after the line 16.
B.after the line 17.
C.after the line 18
D.none of above
answer:C
who can tell me why?