1,520 questions
-1
votes
1
answer
36
views
Unable to pass self.instance_variable as default into a class method
I have a class and method that I am trying to pass a self.instance_variable as default but am unable to. Let me illustrate:
from openai import OpenAI
class Example_class:
def __init__(self) -> ...
0
votes
0
answers
21
views
Instance attributes cannot be passed out of nested functions
When using a GUI design software, an instance variable cannot be accessed outside after being modified inside a nested function triggered by mouse events like on_motion.
The instance attribute stores ...
1
vote
1
answer
64
views
How to reveal class/styles per component such as color and font used in Storybook
I am not a developer, im a designer. My problem is i'm trying to figure out how to reveal more information in Storybook stories so as a Designer I can check content without having to browser inspect ...
4
votes
0
answers
44
views
Why does using 'this' in a Java instance initializer block resolve forward reference errors? [duplicate]
Problem Description
I've encountered an interesting behavior in Java regarding forward references in instance initializer blocks. When I try to access an instance variable directly, I get a forward ...
-2
votes
1
answer
58
views
Well Crafted Patterns To Access Instanced Members Through Static Functions Without The Singleton?
I'm looking for a solution that would allow me to have access to a static function that would operate on instanced values without implementing a singleton. I'm not sure it's possible, I've personally ...
-1
votes
1
answer
44
views
MOOC Java Part 5 How would one know when to use an object as a reference variable in another class?
In Part 5 Primitive and Reference variables section, there is a Person class defined and then another class called TimeMachine which has a reference variable defined for type Person.
public class ...
0
votes
3
answers
475
views
Python Class Variables Vs Instance Variables
class Animal:
x = {}
y = 0
def __init__(self):
pass
animal1 = Animal()
animal2 = Animal()
animal1.x['num'] = 14
animal1.y = 14
print(animal2.x)
print(animal2.y)
Output:
{'num': ...
-2
votes
2
answers
57
views
How can I determine when is more convenient to use static methods instead of instance ones? Encapsulation is the preferable choice?
I am basically writing static methods that perform work on a list of strings but I can't quite determine if it would be better to create instance variable and do all the work internally.
In case my ...
0
votes
1
answer
57
views
What happens to consumer flow for instance when replaced by another one
I have a class which has an internal instance of another class.
@Singleton
class ClassA {
private var classBInstance: ClassB
init{
classBInstance = ClassB()
}
fun ...
0
votes
1
answer
56
views
How does the Setter method work in Java in this example :
In the Setter Method "setName()",
int the first line,
name=this.name ; takes the value of the string "nidhi"
in the second line,
this.name=name;
what actually happens i can't ...
0
votes
0
answers
32
views
Java subclass vs superclass inherited variables clarification [duplicate]
ABOUT ME:
I am learning Java because I want to become a software developer someday and I came across the topic of subclasses and their ability to inherit from superclasses on tutorialspoint.com.
where ...
1
vote
2
answers
105
views
How to update a class attribute when an instance attribute changes?
I am working on optimization problems. As you know, optimization is an iterative process. Some sections are selected, and the weight of all sections is calculated.
I have code like this:
class Test:
...
0
votes
2
answers
59
views
Python - classes and methods
I am trying to create a class called trader that has instance attributes price, action and number, where action is an empty list and number is initially set to 0.
Within this class, i need to define a ...
-1
votes
2
answers
85
views
Why is a private variable of type HashSet is being shared among object instances of the class? [closed]
I recently stumbled upon this weird behaviour of Java where a variable of type Hashset, which is declared private in the parent class, is not unique for each instance of the child. Instead, all the ...
2
votes
2
answers
312
views
Is there any cool way to express `if x is None: x = self.x` in python class?
I'm just studying python OOP, and truly confused when to use self and not.
especially when I want to make a method that defaultly get object instance input and also wanna make it work as a normal ...