1,522 questions
-2
votes
0
answers
59
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{
...
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 ...
0
votes
0
answers
24
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 ...
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 ...
-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 ...
-2
votes
2
answers
67
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
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 ...
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:
...
-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 ...
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 ...
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 ...
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
...
0
votes
0
answers
163
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
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 ...
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
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 ...
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 ...
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 ...
-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
...
-3
votes
1
answer
265
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 ...
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
...
2
votes
1
answer
482
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
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
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 ...
-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()
}