non-static is a term to define a function or field that is bound to some object instance. Without an instance, non static fields cannot be accessed and non static methods cannot be invoked. Unlike static, non-static methods can be overridden (virtual).
Questions tagged [non-static]
525 questions
2
votes
0 answers
How to instantiate non-static inner class?
I have an inner class, which I want to instantiate from the static method of the parent class as follows:
public class MyClass {
public class B {
private int v;
B(int x) {
v = x;
}
public void pr() {
…

user3243499
- 2,953
- 6
- 33
- 75
2
votes
1 answer
Non-static member functions with no ref-qualifier
This is a follow-up to my previous post
With reference to Non-static member functions
Under
const-, volatile-, and ref-qualified member functions
A non-static member function can be declared with no ref-qualifier,...
During overload resolution,…

Vinod
- 925
- 8
- 9
2
votes
2 answers
Why is accessing a non static method from static method is Bad design
I am accessing non static method from static Method. Below is the code. I read its bad design source. Why this bad design please help me to understand.
If so how can one achieve it.
#include
class Base
{
public :
static Base*…

rim
- 351
- 2
- 15
2
votes
1 answer
NodeJS: Can a static method call the constructor of the same class?
I've got a question: If I have a constructor in a class:
module.exports = class ClassA{
constructor(stuffA, stuffB) {
this.stuffA = stuffA;
this.stuffB = stuffB;
}
NonStaticMethod() {
console.log(this);
}
static…

Lenny Will
- 549
- 1
- 4
- 11
2
votes
1 answer
Why does PHP allow calling non-static methods statically but does not allow calling non-static properties statically?
Why does PHP allow calling non-static method statically using Class Names and by the various keywords such as self, static & parent which are placeholders for Class Names?
But on the other hand it does not allow calling non-static properties
…

Mohammad Daud Ibrahim
- 146
- 1
- 2
- 13
2
votes
1 answer
Non-Static method from a static context [Comparing two sets of class instances]
I've read up and understand what the error itself means and generally how to solve it, however I'm not sure how to in the case where I'm creating two different sets of instances from two different classes (comparing if two rectangles collide), and…

George
- 45
- 6
2
votes
2 answers
Static and non-static synchronization, why the output results differ?
Why is there a difference in output? I have 2 cases:
In first case I use static functions f1 and f2:
public static synchronized void f1() {
for (int i = 0; i < 100; i++)
System.out.print("A");
}
public static synchronized void f2() {
…

kurumkan
- 2,635
- 3
- 31
- 55
2
votes
3 answers
When do non static blocks run in java?
class parent {
parent() {
System.out.println("parent");
}
}
public class child extends parent {
{
System.out.println("non static block");
}
child() {
super();
System.out.println("idk");
}
…

anuj
- 31
- 2
2
votes
2 answers
how to resolve Non-Static method cannot be referenced from a static context?
class Base {
Base show() {
System.out.println("Base");
return new Base();
}
class Child4 extends Base {
Child4 show() {
System.out.println("Child4");
return new Child4();
}
…

Disha
- 41
- 1
- 1
- 4
2
votes
4 answers
Non-static method reference?
A little side project I've been doing for fun involves subtracting the current date from a future date given by the user to return the days between them.
public int getDaysBetween(int date2)
{
//Subtract current date from future date (date2),…

Invictus
- 23
- 5
2
votes
1 answer
Non-Static member variables creation like static singleton creation in C++
First, I really like the pattern of lazy initialization of singletons. I use it in the following way to get different kind of data with varying value types (The example is simplified):
class A
{
template
const T& getData() const
…

Nikolaus Ammann
- 507
- 1
- 4
- 12
2
votes
4 answers
Upcasting Objects - difference of static and non-static type
I have the following java code:
class A {
int someMethod () { return 1; }
int someMethod (A a) { return 2; }
int someMethod (B b) { return 3; }
int someMethod (C c) { return 4; }
static A anotherMethod ( Object obj) { return (A) obj; }
…

knacker123
- 79
- 9
2
votes
2 answers
Calling non-static method from another non-static method
Given myClass below and the non-static method run(), the following line of code is valid:
new myClass().move();
However, this is also valid:
move();
I understand the first attempt (new myClass().move()) creates an instance of the class and then…

sedeh
- 7,083
- 6
- 48
- 65
2
votes
1 answer
Fill non-static variable in static class (Spinner)
I am trying to make this:
In DatePickerDialog user set a date
Date will be written in Spinner
The problem is that DatePickerFragment class which includes OnDateSet method is static and the spinner is non-static. In OnDateSet method I need to add…

Filip
- 95
- 10
2
votes
5 answers
Java: static-non-static-this problem
$ javac TestFilter.java
TestFilter.java:19: non-static variable this cannot be referenced from a static context
for(File f : file.listFiles(this.filterFiles)){
^
1 error
$ sed -i 's@this@TestFilter@g'…

hhh
- 50,788
- 62
- 179
- 282