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
-2
votes
2 answers

Python -- reference variables that don't exist

I was learning the tkinter package in Python and I didn't understand next code: import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.pack() …
akerbeltz
  • 39
  • 1
  • 9
-2
votes
2 answers

In a class, what is the difference between instance variable and variable without modifier in c#

In the following code: public class Foo { private object first; object second; public void Bar() { first = "1234"; second = "1234"; } } What is the difference between two declaration? I'm new to OOP and was wondering what…
JNA
  • 45
  • 9
-2
votes
1 answer

Access Instance variable in ruby

I am trying to run the code below in ruby. I am getting a nil value for @selectcells. Any suggestions? class Neighbor_finder @@path = "/home/xyz" def initialize(enodebid,earfcn_dl,distance,spread,mcc,mnc) @site_details=Hash.new @radius =…
ssharma
  • 91
  • 2
  • 13
-2
votes
1 answer

Understanding for returning an instance variable without a method to return it

So I'm just looking for clarification. I have an equals method that is able to return the instance variable by cv.ch of a passed object with out a method to return it. How is this so? public static class Test { private int v; private char…
Kayracer
  • 169
  • 3
  • 13
-2
votes
1 answer

Set Instance Variable from Method using Java

As the title explains I am hoping to be able to set an Instance Variable using data produced by a calculation contained within a Method. I produced an example code to demonstrate what I'm trying to do, as well as a solution I pieced together after…
DeezNuts
  • 11
  • 1
  • 3
-2
votes
1 answer

Add elements to an array using instance methods

I want to add elements to an array. Each time, elements are passed as parameters by calling a different method. That is, calling the following: new_register = CashRegister.new new_register.add_item("eggs", 1.99) new_register.add_item("tomato", 1.76,…
Keren
  • 217
  • 1
  • 6
  • 20
-2
votes
1 answer

How to add a number to a instance variable?

public class Geniegotchi { private String name = "Bob"; private int endurance = 4; private int happiness = 3; public void setName(String newName){ name = newName; } public void setEndurance(int newEndurance){ endurance =…
-2
votes
1 answer

Can I have a straightforward constructor generated from declarations only?

I have a class with many instance variables: class Data { public: const double a, b, c, d; const size_t e, f, g, h, i, j; const std::string s; // and so on double Q, Z; Data(const double a, const double b, ...); }; and some…
David Z
  • 128,184
  • 27
  • 255
  • 279
-2
votes
1 answer

Calculation/variable returning as zero

I am setting up a basic geometry class where I define a rectangle and can manipulate the width and height along with calculating the area and perimeter. Everything works and outputs fine, except the perimeter and area variables return as zero. I…
user3223880
  • 65
  • 1
  • 10
-2
votes
6 answers

Confusion over method parameter and instance variable having same name

class Employee { public String name = "John"; public void modifyName(String name) { name = name; // I know using 'this' would be helpful, but I dont want to } System.out.println(name); } …
ilakk
  • 69
  • 1
  • 8
-2
votes
2 answers

How to combine multiple variables in Rails?

I have Sportists with multiple disciplines and each discipline has one record. I'd like to display the record and in db they are saved as m100rec, m200rec and so on. Is there a way I could display them like so: @discipline + "rec" ? I have saved…
Xeen
  • 6,955
  • 16
  • 60
  • 111
-2
votes
1 answer

Instance variables and Objects, Defining classes

I was given a problem to solve: A Book, which as a title, author, and year of publication. Include methods to get and set the private instance variables and a toString method to display the object. Also create a method moreRecent which takes two…
Freedom
  • 347
  • 2
  • 7
  • 24
-2
votes
1 answer

How can I use string interpolation to sequentially name instances of an object?

I have a class called Team. I am trying to create many instances of it and call them team1, team2, etc. I am trying something like for x in (1..20) instancename="team#{x}" instancename=Team.new end I am getting the memory address of the string…
-2
votes
1 answer

Rails - Trying to display current page number

Routes match '/user/:username/:pagenum' => 'vines#user' Controller def user @username = params[:username] @page = params[:pagenum] respond_to do |format| format.html format.json end …
-2
votes
2 answers

How do you change an instance variables property from a different class

If I had a label in one class and wanted to change what text it displayed, how could I this from a different class?
user1628311
  • 166
  • 1
  • 3
  • 12
1 2 3
99
100