Skip to main content

Static fields and methods are connected to the class itself and not to its instances. If you have a class A, a 'normal' (usually called instance) method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. YouYour main could look like this then:

class Programm { public static void main(String[] args) { Programm programm = new Programm(); programm.start(); } public void start() { // can now access non-static fields } } 

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm { public static void main(String[] args) { Programm programm = new Programm(); programm.start(); } public void start() { // can now access non-static fields } } 

Static fields and methods are connected to the class itself and not to its instances. If you have a class A, a 'normal' (usually called instance) method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. Your main could look like this then:

class Programm { public static void main(String[] args) { Programm programm = new Programm(); programm.start(); } public void start() { // can now access non-static fields } } 
improved code formatting
Source Link
deHaar
  • 18.7k
  • 11
  • 48
  • 57

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm {     public static void main(String[] args) {   Programm programm = new Programm();   programm.start();   }     public void start() {   // can now access non-static fields   } } 

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm { public static void main(String[] args){ Programm programm = new Programm(); programm.start(); } public void start(){ // can now access non-static fields } } 

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm {     public static void main(String[] args) {   Programm programm = new Programm();   programm.start();   }     public void start() {   // can now access non-static fields   } } 
fixed grammar
Source Link
Mark
  • 191.5k
  • 32
  • 557
  • 580

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has so no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm { public static void main(String[] args){ Programm programm = new Programm(); programm.start(); } public void start(){ // can now access non-static fields } } 

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has so no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm { public static void main(String[] args){ Programm programm = new Programm(); programm.start(); } public void start(){ // can now access non-static fields } } 

Static fields and methods are connected to the class itself and not its instances. If you have a class A, a 'normal' method b, and a static method c, and you make an instance a of your class A, the calls to A.c() and a.b() are valid. Method c() has no idea which instance is connected, so it cannot use non-static fields.

The solution for you is that you either make your fields static or your methods non-static. You main could look like this then:

class Programm { public static void main(String[] args){ Programm programm = new Programm(); programm.start(); } public void start(){ // can now access non-static fields } } 
fomatting beautification
Source Link
user2535467
user2535467
Loading
Loading
deleted 1 character in body
Source Link
Chris Farmer
  • 25.5k
  • 37
  • 125
  • 170
Loading
Source Link
Mnementh
  • 51.5k
  • 49
  • 152
  • 202
Loading