MCQ Single Best Answer Moderate

Q
[Object Oriented Programming]
Which of the following statements are valid for static member methods of a class?

I. They can access static as well as non-static data members.
II. They can call non-static member methods.
III. They cannot refer to this or super.

ID: #24944 Competency focused Practice Questions ISC Class XII Computer Science 2 views
Question Info
#24944Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A I and II
  • B II and III
  • C I and III
  • D Only III
Correct Answer: Option D

Explanation

[Object Oriented Programming]
Which of the following statements are valid for static member methods of a class?

I. They can access static as well as non-static data members.
II. They can call non-static member methods.
III. They cannot refer to this or super.
(a) I and II
(b) II and III
(c) I and III
(d) Only III
Correct Answer: (d) Only III

Understanding Static Methods:

A static method belongs to the class itself rather than to any specific object.

static void display() { // static method }

Since static methods belong to the class, they can be called without creating an object.

Now Analyze Each Statement:

Statement Analysis Valid / Invalid
I. They can access static as well as non-static data members. Static methods can directly access only static members. Non-static members belong to objects, so they cannot be accessed directly inside a static method. Invalid
II. They can call non-static member methods. Static methods cannot directly call non-static methods because non-static methods require an object reference. Invalid
III. They cannot refer to this or super. this and super refer to objects. Since static methods are class-level methods and not object-level, they cannot use this or super. Valid

Important Rule:

Static methods can directly access only static members.

Example:

class Test { static int x = 10; int y = 20; static void show() { System.out.println(x); // Valid // System.out.println(y); // Invalid because y is non-static } }

Why this and super Cannot Be Used?

The keywords:

  • this → refers to current object
  • super → refers to parent class object

But static methods work without objects. Therefore, these keywords are not allowed inside static methods.

Final Conclusion:

Only statement III is correct.

Correct Answer: (d) Only III

Share This Question

Challenge a friend or share with your study group.