Hi, this 2 questions are from
www.go4java.20m.com mockexam 1. Q.13 my problem is how can an instance created with a null value ends up calling the constructer that takes string as parameter.
Q.14 just fail to understand
please help.
kavita desai
Q13.What will be the result of compiling and running the given program?
Select one correct answer.
1 class sample
2 {
3 sample(String s)
4 {
5 System.out.println("String");
6 }
7 sample(Object o)
8 {
9 System.out.println("Object");
10 }
11 }
12 class constructor
13 {
14 public static void main(String arg[])
15 {
16 sample s1=new sample(null);
17 }
18 }
ans: Program compiles correctly and prints "string" when executed.
--------------------------------------------------------------------------------
Q14.What will be the result of compiling and running the given program?
Select one correct answer.
1 class sample
2 {
3 sample(String s)
4 {
5 System.out.println("String");
6 }
7 sample(StringBuffer sb)
8 {
9 System.out.println("StringBuffer");
10 }
11 }
12 class constructor
13 {
14 public static void main(String arg[])
15 {
16 sample s1=new sample(null);
17 }
18 }
ans: Compile time error as call to constructor at line no. 16 is ambigious.