What will be the result of the work of the following program?

class A {
  public A() { System.out.print("A "); }
}

class B {
  public B() { System.out.print("B "); }
}

public class Test {
  private A objA = new A();
  private static B objB = new B();

  public Test() {
      System.out.print("Test ");
  }

  public static void main(String[] args){
    System.out.print("Main ");
    new Test();
  }
}
Explanation
The initialization of the fields occurs before calling the constructor and the static fields - when the class is loaded in memory.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes