non-static method cannot be referenced from a static context

HPL

Aktives Mitglied
Das:

Java:
import java.util.Random;

class Probe2
{
   public void MR(){ System.out.println(Random.nextInt(6)); }


   public static void main(String[] args)
    {
        Probe2 p = new Probe2();
       p.MR();
    }
}

führt beim Kompilieren hierzu:

non-static method nextInt(int) cannot be referenced from a static context
public void MR(){ System.out.println(Random.nextInt(6));

Eine statische Methode ist meines Wissens nicht an ein Objekt gebunden.
Ist es möglich nextInt() in eine statische Methode zu verwandeln oder was soll ich tun?
 

Zurück
Oben