Java OCA OCP Practice Question 1624

Question

Which statements, when inserted at (1), will not result in compile-time errors?.

public class Main {
  int count;
  static int light;

  public void m() {
    int i;
    // (1) INSERT STATEMENT HERE
  }
}

Select the three correct answers.

  • (a) i = this.count;
  • (b) i = this.light;
  • (c) this = new Main();
  • (d) this.i = 4;
  • (e) this.light = count;


(a), (b), and (e)

Note

Non-static methods have an implicit this object reference.

The this reference cannot be changed, as in (c).

The this reference can be used in a non-static context to refer to both instance and static members.

However, it cannot be used to refer to local variables, as in (d).




PreviousNext

Related