QUESTION 53 Which one of the statement given in options is false about an "Instance Variables"?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
QUESTION 53
Which one of the statement given in options is false about an "Instance Variables"?
Show answer & explanation
Instance variables are not sharable across objects—each object instance has its own independent copy of instance variables with separate memory locations. Options A, B, and C are all correct: instance variables must be accessed via object references, are allocated fresh memory for each new object, and cannot be declared with the static keyword (which would make them class variables, not instance variables). Option D incorrectly claims shareability, which contradicts the fundamental definition of instance variables.
Step-by-step Derivation:
Instance variable properties:
- A) Correct: Instance variables require object reference:
myObj.age = 25; - B) Correct: Each
new Object()allocates fresh memory for all instance variables. - C) Correct: Declaring with
staticconverts it to a class variable, not instance. Valid:private int var;Invalid:private static int var;(for instance vars) - D) FALSE: Instance variables are NOT sharable. Each object has isolated copies. For sharing across objects, you need
staticclass variables.
Example:
class Student {
int age; // instance variable, NOT shared
}
Student s1 = new Student();
Student s2 = new Student();
s1.age = 20; // s1's copy
s2.age = 25; // s2's separate copy (not affected by s1)
s1.age ≠ s2.age always, proving non-shareability.