S
Skara
Gast
Hallo,
ich will wie im Code in der main Methode zu sehen ist, ein Object namens KObject erstellen, welches in einer inneren Klasse definiert ist. Dabei kommt folgender Fehler:
No enclosing instance of type KnapSackFractional is accessible. Must qualify the allocation with an enclosing instance of type KnapsackFractional.
Setze ich vor das "new" "ein KObject.", sagt er mir, dass es nicht zu einer Variable aufgelöst werden kann.
Was mache ich falsch? =S
ich will wie im Code in der main Methode zu sehen ist, ein Object namens KObject erstellen, welches in einer inneren Klasse definiert ist. Dabei kommt folgender Fehler:
No enclosing instance of type KnapSackFractional is accessible. Must qualify the allocation with an enclosing instance of type KnapsackFractional.
Setze ich vor das "new" "ein KObject.", sagt er mir, dass es nicht zu einer Variable aufgelöst werden kann.
Was mache ich falsch? =S
Java:
public class KnapsackFractional {
class KObject {
private String name;
private int gewicht;
private int nutzen;
private float anteil;
KObject (String name, int gewicht, int nutzen, float anteil) {
this.name = name;
this.gewicht = gewicht;
this.nutzen = nutzen;
this.anteil = anteil;
}
}
public static void main(String[] args) {
KObject test = new KObject ("bla", 5, 6, 0);
}
}