Skip to content
Sharp

Object-oriented programming · interview question

Why might using 'this' in static methods result in an error?

Multiple choiceHardchapter-2-curatedpremiumoopthis-keyword
Choose one answer
Answer and explanation

Correct answer

B. 'this' refers to instance data, which is not accessible in static methods.

Why

'this' refers to the current instance of a class, but static methods belong to the class itself. Since static methods don't have an instance context, 'this' cannot be used inside them.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →