Java - Classes and ObjectsWhat is true about instance variables in Java?AThey belong to an object and each object has its own copy.BThey are shared by all objects of a class.CThey must be declared inside a method.DThey cannot have access modifiers.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand instance variable ownershipInstance variables belong to objects, so each object has its own copy.Step 2: Compare with other variable typesStatic variables are shared by all objects, but instance variables are not.Final Answer:They belong to an object and each object has its own copy. -> Option AQuick Check:Instance variables = belong to object [OK]Quick Trick: Instance variables belong to objects, not the class itself. [OK]Common Mistakes:Confusing instance variables with static variables.Thinking instance variables are declared inside methods.Assuming instance variables cannot have access modifiers.
Master "Classes and Objects" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Abstraction - Partial abstraction - Quiz 5medium Abstraction - Abstract methods - Quiz 1easy Classes and Objects - Class definition - Quiz 11easy Constructors - Constructor overloading - Quiz 14medium Encapsulation - Data hiding - Quiz 15hard Encapsulation - Getter and setter methods - Quiz 5medium Inheritance - Method overriding - Quiz 13medium Inheritance - Method overriding - Quiz 3easy Interfaces - Interface declaration - Quiz 7medium Polymorphism - Compile-time polymorphism - Quiz 2easy