MCQ
Single Best Answer
Moderate
Q
[Object Oriented Programming]
Which one of the following keywords will make the data member a class variable?
Which one of the following keywords will make the data member a class variable?
ID: #24945
Competency focused Practice Questions ISC Class XII Computer Science
4 views
Question Info
#24945Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option A
Explanation
[Object Oriented Programming]
Which one of the following keywords will make the data member a class variable?
Which one of the following keywords will make the data member a class variable?
Correct Answer: (a) static
Explanation:
In Java, a class variable is a variable that belongs to the class rather than to individual objects.
What is a Class Variable?
- Shared by all objects of the class
- Stored in class memory (not object memory)
- Declared using the static keyword
Use of static Keyword:
class Test
{
static int count = 0; // Class variable
}
Here, count is shared among all objects. If one object changes it, the change is reflected for all objects.
Example:
class Demo
{
static int x = 10;
}
public class Main
{
public static void main(String[] args)
{
Demo obj1 = new Demo();
Demo obj2 = new Demo();
obj1.x = 20;
System.out.println(obj2.x); // Output: 20
}
}
Since x is static, both objects share the same variable.
Why Other Options are Wrong?
- final → Makes variable constant (cannot change value)
- abstract → Used for classes/methods, not variables
- public → Access modifier (controls visibility, not type of variable)
Conclusion:
To make a data member a class variable → use static keyword
Therefore, the correct answer is: (a) static
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic