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

In Java, can 1 instance variable have 2 potential values?

I have been instructed to "Write a class, Triangle, with one instance variable that takes two string values, (filled or not filled)". I'm new to Java, and still haven't come across a situation where you could have two potential values for one…
Stephanie
  • 1
  • 3
-1
votes
10 answers

local variable and instance variable. Java

So I was testing some code and here they are: public class Phone { String phoneNumber = "1234"; void setNumber(){ String phoneNumber; phoneNumber = "4321"; } } public class TestPhone { public static void…
OPK
  • 4,120
  • 6
  • 36
  • 66
-1
votes
3 answers

How can I call a method on an instance within the instance class?

public class Agent { private Space _location; private String _name; public void setLocation(Space space){ _location = space; } public void usePortal(){ if(_location.getPortal() !=…
Ortech
  • 21
  • 3
-1
votes
1 answer

I am having trouble creating a method, and iterating through an array within the method in Ruby

I am writing a simple cookbook app in Ruby, and I am stuck. It's a practice module that I am working on. Here are the instructions for the current ste "Implement the following methods so that the added code works. The comments next to the code…
-1
votes
2 answers

PHP: What does -> appearing more than once in a statement mean?

I understand that in $page->$blocks= 'blocks'; $page is an object, $blocks is its field, and here we are assigning the string 'blocks' to the instance variable $blocks which belongs to the instance $page. But what about $this -> blocks ->…
Solace
  • 8,612
  • 22
  • 95
  • 183
-1
votes
2 answers

Difference between self.name and _name using modern Objective-C

Say this is in my header file: @interface AppDelegate : NSObject @property (weak) IBOutlet NSSlider *slider; - (void)doSomething; @end …and this is the *m: @implementation AppDelegate - (void) doSomething {[self.slider…
user3688749
-1
votes
1 answer

PHP objects and instances

I'll break it down as simple as possible then post all the necessary code. Goal: to get all answers for each sub period in a period for all the users, and the ones that don't have one i will mark the cells (don't worry about this part) so i can…
-1
votes
2 answers

Undefined method error on an instance method

To preface this, I am new to ruby and rails but I have done my homework and I really thought I was doing this right. So in my rails controller, I am loading another class called Input. I want to create an instance of the Input class and then call…
-1
votes
2 answers

Understanding the scope of child/parent instance variables

I have a question regarding variable scope with subclasses. I have something like the following: ParentClass.h @interface ParentClass : NSObject @property (nonatomic, strong, readonly) NSString *myIdentifier; - (id)initWithIdentifier:(NSString…
Joseph
  • 9,171
  • 8
  • 41
  • 67
-1
votes
1 answer

Using a return value from a method

I have a Menu class with a method that displays a menu, stores and then returns the selection made by the user. public class Menu { public static int menuSelect(){ Scanner input = new Scanner(System.in); …
moebeeable
  • 11
  • 3
-1
votes
2 answers

Declared boolean on object, doesn't change his value

I was just figuring out how instance variables are working, but it lead me to something strange. public class DrumKit { boolean topHat = true; boolean snare = true; void playTopHat() { System.out.println("ding ding da-ding"); …
-1
votes
4 answers

How to to Use Reflection in C# to Execute Method by name?

I Want to use Reflection to execute my function(Which name is GetAverage,With no parameter) And this function is in class by name of Gold. I Use This Code : string MyFunction = "GetAverages"; Type type = typeof(MyGoldClass); MethodInfo info =…
Amin AmiriDarban
  • 2,031
  • 4
  • 24
  • 32
-1
votes
3 answers

Instance of class as an private field object in another class? How?

There is defined class Saturn. Define class SolarSystem which contain as a private field an object from Saturn class. In class SolarSystem: define constructor which could initialize private field which will be an object from Saturn class. public…
krzyhub
  • 6,285
  • 11
  • 42
  • 68
-1
votes
1 answer

Ruby deduct from instance variable same values from other

I have two instance values: @a, and @b, there are hash-like.... (will explain on pseudo examples) For example in @a i have: *Field1 | Field2 | Field3* CONTITECH | CT942K1 | 123 CONTITECH | CT722K1 | 123 ATE | AB2123 | 123 in @b i have: CONTITECH |…
Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47
-1
votes
2 answers

Objective C: Methods and instance variables

PrefMySpotsViewCtrl.h @class Location; @interface PrefMySpotsViewCtrl : NSViewController { NSTextField *locationSearchInput; NSString * enteredLocation; Location *l; } @property (nonatomic, retain) IBOutlet NSTextField…
grep
  • 566
  • 5
  • 20