Computer Science, asked by ben2038, 1 year ago

define instance variables.​

Answers

Answered by vikrantraj15
0

Answer:

an instance variable has a name beginning with @, and its scope is confined to whatever object self refers to. Two different objects, even if they belong to the same class, are allowed to have different values for their instance variables. From outside the object, instance variables cannot be altered or even observed (i.e., ruby's instance variables are never public) except by whatever methods are explicitly provided by the programmer. As with globals, instance variables have the nil value until they are initialized.

Instance variables of ruby do not need declaration. This implies a flexible structure of objects. In fact, each instance variable is dynamically appended to an object when it is first referenced

Answered by ayaankhan01
2

Answer:

An instance variable is a variable that is a member of an instance of a class (i.e associated with something created with a new), whereas a class variable is a member of the class itself.

Every instance of a class will have its own copy of an instance variable, whereas there is only 1 of each static (or class) variable, associated with the class itself.

Similar questions