Questions tagged [instance-variables]

In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy.

In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy.

1506 questions
-1
votes
3 answers

Assigning nil to a member variable which is passed to a method

I'd like to assign nil to an object, which is an ivar, passed in as a parameter to a method, something like this. - (int)trashObjectPassedIn:(Banana* banana) { banana = nil; return 42; } Of course, if I call it like this: [self…
Josh Paradroid
  • 1,172
  • 18
  • 45
-2
votes
1 answer

confusion because i can't figure out what is changing the attribute of the object of a class in python

Here is my code ` class Cats: def __init__(self,name): self.name=name #print(self.name,name,"hello") def change_name(self,new_name): self.name=new_name return 0 …
-2
votes
1 answer

If define an instance variable which type is the defining class self

What will happen if I define a class like below code with Swift, the complier doesn't give any errors: class Test { var test = Test() }
Peruser
  • 11
  • 1
-2
votes
1 answer

How to edit instance variable in method and read in different method

I'm pretty new to java and could not find a question answering my problem particulary. I initialized an arraylist as instance variable and in one method I edit this arraylist which also works, but I'm having trouble storing this value in the…
-2
votes
1 answer

What can't I print out the value of a instance attribute derived from other instance attributes?

I'm pretty new to Python and I would be really grateful if someone could help me out with this issuer I'm facing. This is my code: class Player: def __init__(self, name): self.name = name self.info = {} self.info_count =…
-2
votes
1 answer

Debugging simple Ruby class method?

class DobbsyKretts def initialize #Receive idea puts "Enter an idea, a secret or anything else you want to secretize; hit enter to stop typing and save the file" (@idea = gets).reverse.upcase #Filename and saving - to encrypt the…
-2
votes
1 answer

Difference Between @ and @@ instance

I produce an app with ruby, and benefited from ruby tutorials. So, I meet this syntax (@@vars), and want to ask it. (I think it's like a pointer in C or two dimensional array) @@vars AND @vars
Hakan Ilgar
  • 141
  • 5
  • 14
-2
votes
3 answers

Printing out Savings the second time

So I already have coded mostly everything but I need help with one part which is all the way at the bottom of the code. So I made an object with a saving of 2531.5 so i can print that out as the initial saving of Mr. Gob's but then you have to add…
-2
votes
2 answers

Pass object of any type to class B

I want to be able to pass Object from any class to a specific class. How do i do this? I pass the object in the constructor of the receiving class. One workaround i know is using static variables, but i need the whole object not just the variables. …
-2
votes
2 answers

Real word simulation of a Printer using Queue in Python

I am going through the book "Problem Solving with Algorithms and Data Structures using Python" In the chapter for Queues there is a printer simulation with the Printer class. here is the definition of Printer class: class Printer(): def…
-2
votes
1 answer

Accessing object variables by class name instead of this

Usually when there is getter/setter in a POJO class, the general convention I have seen until now was to use return this. / this. = something But, the current project I am working on uses a strange convention of…
Sara
  • 603
  • 8
  • 19
-2
votes
2 answers

My GUI is not recognizing my instance method. How can I fix this?

1) I can not call my instance method in the GUI 2) I can not implement a specific feature. I have two basic problems. First of all, I need my GUI to recognize my instance method (namely, when I call my isWin method in my GUI, the method is not…
-2
votes
2 answers

to change the value of instance variable

I want to print name as tanya but since self.name = None has been assigned in constructor it is printing None. So how to get tanya printed when the check function gets called: class A: def __init__(self): self.name = None def…
lavanya
  • 1
  • 1
-2
votes
1 answer

Pygame: static variables and instance variables

I know that static variables apply to an object and an instance variable (usually under the __init__() function) applies to an instance but a question came to mind: When and where should static variables and instance variables be used in a game?…
-2
votes
1 answer

How to Change a String on your Array

Well I have an array of people. They contain instance variables such as: NAME, AGE, LOCATION. These are private instance variables. Now there are various of people in my array with their own instance variables. Ill use myself to make it…
EspadaAzul
  • 23
  • 4