English

State any one difference between instance variable and class variable.

Advertisements

Questions

State any one difference between instance variable and class variable.

Differentiate between instance variable and class variable. 

Distinguish Between
Advertisements

Solution 1

  1. Each instance variable is created separately, but class variables are created once and shared by all class objects.
  2. Instance variables are defined without the static keyword, whereas class variables are declared with the static keyword in a class.  
shaalaa.com

Solution 2

S. No. Instance variable Class variable
1. Instance variables are defined without the 'static' keyword.

Class variables are defined using the Keyword 'static'.

2. Instance variables are separate copies of an object. A static variable (class variable) will be accessible as a singular shared instance for all class instances.
shaalaa.com
Object as an Instance of a Class
  Is there an error in this question or solution?
Chapter 6: Class as the Basis of all Computation (Objects and Classes) - EXERCISES [Page 384]
Advertisements
Share
Notifications



      Forgot password?
Use app×