Multiple choice java

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


public class Hope{
    public static void main(String argv[]){
        Hope h = new Hope();
    }
    protected Hope(){
        for(int i =0;
        i <10;
        i ++){
            System.out.println(i);
        }
    }
}

  1. Compilation and running with output 0 to 9

  2. Run time error: Constructors cannot be declared protected

  3. Compilation error: Constructors cannot be declared protected

  4. Compilation and running with output 0 to 10

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The class has a main method creating an instance of Hope. The constructor is protected. Since the instantiation happens within the same class (Hope), the protected modifier allows access. The loop runs from 0 to 9 (since i < 10), printing 0 to 9.