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
-3
votes
1 answer
How to access protected inherited non static method in static method(ex main method) of other package?
By creating instance of parent class we can't access its inherited method in other package as it is not direct inheritance. Even directly we cant use non static because our child method is static whereas parent class method isn't. ex
package…

user8604773
- 3
- 1
-3
votes
1 answer
non-static method run(JFrame,int,int) cannot be referenced from a static context
I wrote this code, it allows to select a file and get the filename and its directory:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class NewsReader
{
static String filename = "";
static String directory = "";
…
-3
votes
1 answer
Why is a non-static variable in a function being initialized to 0 and why is it becoming static?
I'm attempting to run the following C code
#include
void myFunc() {
static int a;
int b;
a++;
b = b + 2;
printf("a:%d, b:%d\n",a,b);
}
int main(void) {
myFunc();
myFunc();
return 0;
}
The result I get…

keaek
- 15
- 1
-3
votes
2 answers
Invalid use of non-static member function - Class Member Function Calling Another Class Member Function
I keep getting this message when I try to compile:
task.c++:54:102: error: invalid use of non-static member function
this->createTask(&otherTask, this->otherMain, mainTask.regs.eflags, (uint32_t*)mainTask.regs.cr3);
Here is my task.c++…

amanuel2
- 4,508
- 4
- 36
- 67
-3
votes
1 answer
An object reference error messages is required for the non static field or property method
I have one problem, as shown below, although both are public and BUS 2 class has a reference to DAO, but still an object reference error messages is required for the non static field or property method.
Image DAO
Image BUS
-3
votes
1 answer
Which method am I calling that is static?
So heres my code:
package project;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import…

Rep0man
- 1
-3
votes
4 answers
How do i change a variable of another class?
I have a variable in the class "MainActivity" with the name modeNr, it is protected so it should be accessible from within the package, however whenever I try to alter it from a class in the same package it gives the error: "Non-static field…

NoahKr
- 1
- 4
-3
votes
1 answer
Java non-static variable
I am trying to create ball collisions using two ball sprites. When one ball collides its speed should depend on the other balls initial speed, so in the sprites I need to call in the speeds of the other ball, but I can't figure out how to get past…

krismosel
- 5
- 1
- 4
-4
votes
1 answer
When does the non-static block get executed in java?
I expected that non-static blocks always execute at the time of object creation. But in the following example I called the static method but the non-static block executed. I've not created any object so why does the non-static block execute?
class…

Albertkaruna
- 85
- 2
- 11
-4
votes
1 answer
Non-static methods cannot be referenced from a static context from within the same class
I have got through most of my code for a Student Registration Interface without difficultly, however I am getting this error.
non-static method cannot be referenced from a static context.
Now, I know this kind of problem is quite common, but it…

SIHB007
- 69
- 1
- 10
-4
votes
2 answers
Non-static reference to static in Java (but I'm only using static)
I'm getting the following errors when this code runs:
Error: Cannot make a static reference to the non-static field c
Error: Cannot make a static reference to the non-static field d
This happens 11 times total with the code:
import…

Sam Mitchell
- 194
- 2
- 18
-5
votes
3 answers
how can add map object to list object non static in java
I have problem with this code,when I add map object to list,all previous added object will be changed.how can I declare map as non static?
for(Statment){
map.put(Key,value),
}
result.add(map);

Arash K
- 13
- 1
- 8
-5
votes
1 answer
Can a static variable be access by nonstatic functions?
My questions is: if a static variable (access level: private) is defined in a class and we want to access it by non static function of that class. . is it possible in c++?

Kamal Ahmad
- 27
- 5
-5
votes
1 answer
Java: error - non-static variable scan cannot be referenced from a static context
I have this error:
non-static variable scan cannot be referenced from a static context
Question has been improved.
1) Posted a code instead of a pic.
2) Improved a formatting and question itself.

Qui-Gon Jinn
- 3,722
- 3
- 25
- 32