Java OCA OCP Practice Question 1209

Question

Which of the following statements is true?

  • A. An instance method is allowed to reference a static variable.
  • B. A static method is allowed to reference an instance variable.
  • C. A static initialization block is allowed to reference an instance variable.
  • D. A final static variable may be set in a constructor.


A.

Note

An instance method or constructor has access to all static variables.

Option A is correct.

static methods and static initializers cannot reference instance variables since they are defined across all instances, making Options B and C incorrect.

They can access instance variables if they are passed a reference to a specific instance, but not in the general case.

Option D is incorrect because static final variables must be set when they are declared or in a static initialization block.




PreviousNext

Related