Font size:
Print
Question:

What will be the result of attempting to compile the following program?
public class MyClass {
long var;
public void MyClass(long param) { var = param; }
//(1)

public static void main(String[] args) {
MyClass a,b;
a = new MyClass();              //(2)
b = new MyClass(5);         //(3)
}

}


1. A compilation error will occur at (1). since constructors cannot specify a return value
2. A compilation error will occur at (2), since the class does not have a default constructor
3. A compilation error will occur at (3), since the class does not have a constructor which takes one argument of type int
4. The program will compile correctly
Prev Question Java compiler javac translates java source code...
Next Question Class members of a class in C++ program are by ...