question of the day

What will happen when you attempt to compile and run the following code?

class Whitney{
private Whitney(){
System.out.println("zero param Whitney");
}
protected Whitney(int i){
System.out.println("int param Whitney");
}
public Whitney(String s){
System.out.println("String param Whitney");
}
}
public class Andhilary{
public static void main(String argv[]){
new Andhilary().go();
}
public static void go(){
hoe(new String("beans"));
}
protected void hoe(String s){
System.out.println(s);
}
}







1.Compile time error, a constructor may not be marked as private
2.Compile time error, the code in the main method is faulty
3.Compile time error caused by a problem in the go method.
4.Compilation and output of "beans"
5.Compilation and output of "zero param Whitney" followed by "beans"


answer in comments

1 comments:

gautam said...

The Correct Answer is
3) Compile time error caused by a problem in the go method.

This code will produce a compile time error with a message such as

Andhilary.java:17: non-static method hoe(java.lang.String) cannot be referenced
from a static context
hoe(new String("beans"));

Post a Comment