1,522 questions
-2
votes
0
answers
58
views
On calling inherited method from parent class by object of child class why instance variable of parent class is printed [duplicate]
class parent{
private String x = "Parent";
public void printmsg() {
System.out.println("value is "+ this.x);
}
}
public class child extends parent{
...
1
vote
0
answers
20
views
Maya shader access instance attributes
I try to write an openmaya viewport 2.0 shader in maya that read couple of vec4 custom attributes on instances for the logic of the shader. Ideally bifrost instances but it can be geo instanced in ...
0
votes
0
answers
129
views
Retrieve the APEX Instance admin SMTP_FROM to use in APEX_MAIL.send
I would like to send emails from APEX or PL/SQL. This works if the FROM parameter is the same as our Instance Administrator has configured in SMTP. I have the email adress, but I would like to ...
-1
votes
1
answer
51
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
23
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
votes
2
answers
200
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
61
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
58
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
1k
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
66
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
65
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
69
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
117
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
67
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
101
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
389
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 ...
0
votes
2
answers
2k
views
I need help creating a Rectangle class with private instance variables, but public methods and constructors
I'm new to using java and I need to make a class called Rectangle, but the code I'm using doesn't seem to work, and the notes for class aren't helpful. I feel like it has something to do with my ...
0
votes
1
answer
218
views
Instance variables in ruby utility module that extends self?
I'm making a utility module that have some simple functions - I want the module to extend self so it does not need to be instantiated. A coworker and I were discussing various ways to store data in ...
1
vote
1
answer
203
views
What is the Julia equivalent to classes and instance variables in Java?
I am trying to avoid repeatedly passing a struct in my functions in order to access its fields. In Java this can be avoided by using a class and defining instance variables. What's the equivalent in ...
0
votes
0
answers
35
views
Problems with referencing and calling methods in another class
I am unsure how to go about setting up a method in a golf Player class. This class calls on other methods of another class called ScoreCard so I will include that class here as well.
Player class:
...
1
vote
2
answers
64
views
How to reference variables in other classes
I just feel like I'm not doing this correctly and I have researched and just can't seem to wrap my head around how to initialize variable that have to reference another method or class.
Player class
...
1
vote
2
answers
114
views
Java arraylist does not keep values that I am passing inside a method
I am making an AI game where the cpu stacks N numbered cubes in a table in 3 rows using the Uniform Cost Search algorithm. What I'm trying to do is the generateMoves() method, which will return an ...
0
votes
0
answers
162
views
How to pass instance of Sequelize into a npm module
this is bit of a loaded quesiton but thought i may give it a go. We have similar db code for diff projects so we decided to wrap Sequelize into its own module. basically, i have this format
const ...
0
votes
0
answers
60
views
Accessing the method of an instance of a Class with instance-name in a variable
Frontend I can access methods of an instance of a class by static code:
instanceName.method(varValue);
The class is Gauge (library SVG Gauge) and with the above code I can control the pointer of my ...
0
votes
2
answers
68
views
How do you access instance variables from a Class object across different Classes within the same namespace in Ruby
Let's say I am working on a problem where a class object will only be instantiated once, such as a Gem configuration object. The configuration class calls many classes that use the configuration class ...
0
votes
1
answer
35
views
Initializer block - whats the flow of this code?
I understand that the following code is allowed (I've read the previous posts on the topic), but can someone explain to me what is actually happening when this class is run? Is the block skipped and ...
1
vote
2
answers
606
views
Passing object to constructor versus getting from static utility class
I am not sure how to design of my Java classes, the question is also related to better testing.
I am using static utility class/method Utils.getMapper() to get configured ObjectMapper at many places ...
0
votes
1
answer
657
views
How to create variables for each row in a React table?
I am rendering a dynamic table in react like this:
<TableBody>
{finalLoadedTokensData.map((loadedToken, index) => {
const isItemSelected = isSelected(loadedToken.contract);
...
0
votes
1
answer
33
views
non-static variable this cannot be referenced from a static context error when creating a new object instance
I am trying to create a new object of teacher and student but it is giving me an error. It stops giving me the error if I remove static from main but then it can't find main to run. I really do not ...
1
vote
2
answers
226
views
How to generate methods to set and get properties at class instantiation with Python?
I have a class containing tensors that have an unpredictable list of properties.
I would like it to generate a list of properties with getters and setter based on a list given at instantiation.
Do hou ...
0
votes
2
answers
68
views
Declare allowed instance variables in class definition?
I'm looking to use class objects to store data from multiple simulations and save them in a list, each entry in the list a new instance of the class). I'd like to ensure that each instance has exactly ...
0
votes
0
answers
29
views
Multithreading create two memory of instance variable
I tried to run two thread of class's function, and in function use instance variable. But when I show the adderss of that instance variable, why the address of self.flag of index = 3 is different with ...
1
vote
3
answers
50
views
Is there any benefit in in having an instance variable within a class which is an instance variable of another instance variable within that class
For example lets say there is a player object with an instance variable:
public class Player {
private final PlayerConnection connection;
private final PacketSender sender;
public ...
0
votes
0
answers
28
views
Need to check class definition for a Package class, unsure if coding is correct?
I am not building the main program, just the class definition - so it's hard for me to check and see if my class definition looks correct.
What I am trying to do:
Create the class definition for a ...
-2
votes
1
answer
69
views
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
...
0
votes
1
answer
612
views
Create an instance of a class passing values of list as arguments in Python [duplicate]
I'm currently try to pass the items of a list create an instance of a class.
My code looks like this
args = ["1", "John", "Doe"]
class Token:
def __init__ = (self, ...
-3
votes
1
answer
263
views
Why does it not need to use the "self" parameter like in Python to define Class in C++? [duplicate]
I am a beginner of C++ with Python background. I have some ambiguity about the process of obtaining instance attributes in Python classes and C++ classes.
As follows, I list two classes that have the ...
0
votes
0
answers
29
views
Not able to access a INSTANCE variable in python
class Atm:
def __init__(self):
self.pin = ""
self.balance = 0
def menu(self):
ask = int(input("""
Select ...
1
vote
1
answer
159
views
Problem encountered while using list as a class variable in python3.8
I am trying to learn the python class variable concepts, while doing so I have encountered below issue. I would appreciate if anyone can help me in understanding why this below mentioned behavior
...
0
votes
2
answers
63
views
Setting the value of a class property via method
So, I have been trying to implement the following:
from abc import ABC
from abc import abstractmethod
class parent(ABC):
@property
@abstractmethod
def example_variable(self)->str:
...
2
votes
1
answer
480
views
Getting a value after the object was created from user input Tkinter Python
I cannot figure this out even though I watched videos about Object Oriented Programming and Classes in python.
Simplified scenario: 2 classes.
class1 is basically a window with two buttons (button1 ...
0
votes
1
answer
455
views
How to change an instance attribute without changing another instance attribute assigned the same value?
I want to create a Library Management System using Python 3.10.8 and OOPs approach.
I want to make two Instance attributes:
1)listOfBooks :containing the list of books available in the Library's ...
0
votes
1
answer
103
views
In a Swift Class how do I use a @Published instance member within a property initializer
I am trying to use a completion handler in a view model that assigns values to @Published variables. I get an error stating I cannot use instance members within the property initializer. I tried ...
2
votes
0
answers
71
views
NameError: name 'First_Nam' is not defined
Bank Program
I have made a class Account with it's own attributes, one of which is First_Nam. Then, in my main() function I assign the value of an input object to an instance of the class Account.
I ...
2
votes
1
answer
2k
views
Better to save method result as class variable or return this variable and use as input in another method?
I don't have any formal training in programming, but I routinely come across this question when I am making classes and running individual methods of that class in sequence. What is better: save ...
0
votes
1
answer
643
views
Typescript - Class Instance Variable As An Accessor To The First Value In A Set [duplicate]
In a typescript class, are you able to specify an instance variable as a shortcut to access the first value in a Set?
What I want to do is something like this:
export class Car {
public gears: Set&...
-2
votes
1
answer
52
views
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()
}
0
votes
0
answers
87
views
Accessing instance variable
I have read from a website that instance variables can be accessed directly within the class but my code below works only with object. can someone please help.Thanks in advance!
public class ...