Habe folgendes Problem: Ich habe zwei Klassen.Klasse a hat 2 Attribute und Klasse b besteht aus einem Feld in dem alle Objekte von Klasse a sind. Jetzt weiß ich nicht wie ich das Feld erstellen kann in dem alle Objekte der anderen Klasse enthalten sind. - Vielleicht indem ich bei dem Kunstruktor bei Klasse a, das Objekt immer noch in einem Feld speicher. Also so:
class punkt{
public double x;
public double y;
public konstruktor(int a,int b){
punkt punkt1 =new punkt();
punkt1.x=a;
punkt1.y=b;
feld[feld.length]=punkt1;}
public static void main(String[]args){int [] feld= new Int;}
}
class polygon {
public punkt[] ecken=feld;,}
Glaub nicht das es so stimmt. Weiß jemand wie es richtig geht?
class punkt{
public double x;
public double y;
public konstruktor(int a,int b){
punkt punkt1 =new punkt();
punkt1.x=a;
punkt1.y=b;
feld[feld.length]=punkt1;}
public static void main(String[]args){int [] feld= new Int;}
}
class polygon {
public punkt[] ecken=feld;,}
Glaub nicht das es so stimmt. Weiß jemand wie es richtig geht?