An instance is a particular occurrence of an object during the time when a computer program is running.
Questions tagged [instance]
19 questions
24
votes
4 answers
Make methods that do not depend on instance fields, static?
Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods that are non-static and do not depend on any…

Random42
- 10,370
- 10
- 48
- 65
22
votes
4 answers
What are the differences between class variables and instance variables in Java?
I'm very new to Java and want to understand the difference between class variables and instance variables.
For example:
class Bicycle {
static int cadence = 0;
int speed = 0;
int gear = 1;
}
How are instance variables and class…

Skylar Adams
- 433
- 2
- 4
- 6
15
votes
4 answers
Singleton or instantiate everytime I use?
I use a class that just extracts data from one known object, and distributes it to other known objects. No persistent configuration or such is needed in that class instance.
How should I decide whether to set up that class as a singleton, or just…

bebbi
- 361
- 3
- 8
7
votes
1 answer
Log4j logger per class vs logger per application
I am stuck at understanding a concept related to Logger creation, especially in the context of Java EE.
In my experience, I nearly always used one logger per application, with few cases when I needed a specific logger for a specific part of the…

XMight
- 185
- 1
- 8
3
votes
4 answers
Why are inheritance and interfaces restricted to instance members?
Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language.
I think that the use of attributes and reflection could be largely reduced if static members…

Louis Somers
- 661
- 5
- 9
2
votes
2 answers
If an object x is an instance of a type T, then what is a type T for a concept C?
In concept-based programming (as in C++ concepts), I am wondering if there is a noun to say that:
A type T is an XXXX of a concept C.
in the same way we can say that:
An object x is an instance of a type T.
More generally what is the associated…

Vincent
- 169
- 6
2
votes
3 answers
Are Instanced APIs a Problem in a C Interface?
So an Instanced API is one that behaves like an object. So for example:
foo* GetInstancedAPI();
void MemFuncSetter(foo* fooThis, const int arg);
int MemFuncGetter(const foo* fooThis) const;
This is as opposed to a non-instanced API which would…

Jonathan Mee
- 169
- 5
2
votes
2 answers
Python OO problem
I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it.
As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some inheritance code.
Class A
def foo
print…

Erik Ros
- 54
- 6
2
votes
2 answers
Objects or primitives as arguments
I have come across the term "garbage disposal" and now I'm worried about using up too much memory. Apparently (correct me if I'm wrong) every time an object is created, memory is reserved for it, and that object must be properly disposed of if not…

Abbrew
- 31
- 2
2
votes
2 answers
observer class as instance
Sometimes I read in observer-pattern descriptions, to make the constructor of a observer base class protected so the class will be abstract. but by making the constructor public (if even one is neccessary), I could use the observer as an instance…

itwasntpete
- 147
- 1
- 6
1
vote
1 answer
How to avoid fetching additional informations when instantiating objects
I'm creating an HTML5 game using javascript and have got some problems during the first instantiation of the objects of the scene.
Scenario
Self-written 2d game engine that supports multiple types of objects.
'Glossary'
An object is a…
user242937
1
vote
5 answers
Understanding basics of object declaration in Java
Is there a case when an object is declared without a call to the constructor?
as in, for example:
ArrayList grades;
Or is it always the case that ArrayList grades (as in our example here) would always be followed by a call to a…

Zvi
- 21
- 4
1
vote
2 answers
Instantiating objects in Java
I'm learning now Java from scratch and when I started to learn about instantiating objects, I don't understand - in which cases do I need to instantiate objects?
For example I'm studying from TutsPlus course about it and there is example about…

davisdev
- 39
- 4
0
votes
1 answer
Identifying the use case for instantiation only through existing instances
I was in my CS class when my instructor presented me the following classes:
public class UninstantiableTest {
private static Uninstantiable uninstantiable;
public static void setUninstantiable(Uninstantiable used) {
uninstantiable…

Addison Crump
- 723
- 1
- 6
- 10
0
votes
2 answers
Does anonymous object instantiation have advantages over static object creation in this specific case?
In a Java program which I did not made and cannot change, only write extensions for it, the design forces me to create an object which will never be garbage collected. I tested and I can do it through the use of statics or anonymous object…

user5950
- 113
- 2