Hallo,
über eine Instanz von clNamen erfasse ich Nachname und Vorname. In der Klasse Test will ich diesen Namen anzeigen lassen. Soweit klappt das auch. Aber warum kann ich den Namen nicht in eine ArrayList packen ?
Alles anzeigen
Alles anzeigen
über eine Instanz von clNamen erfasse ich Nachname und Vorname. In der Klasse Test will ich diesen Namen anzeigen lassen. Soweit klappt das auch. Aber warum kann ich den Namen nicht in eine ArrayList packen ?
Quellcode
- /**
- * Write a description of class clNamen here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class clNamen
- {
- // instance variables - replace the example below with your own
- private int x;
- private final String sName;
- private final String sVorname;
- /**
- * Constructor for objects of class clNamen
- */
- public clNamen(String sName, String sVorname)
- {
- // initialise instance variables
- x = 0;
- this.sName = sName;
- this.sVorname = sVorname;
- }
- /**
- * An example of a method - replace this comment with your own
- *
- * @param y a sample parameter for a method
- * @return the sum of x and y
- */
- public int sampleMethod(int y)
- {
- // put your code here
- return x + y;
- }
- public String gibName()
- {
- return sName;
- }
- }
Quellcode
- import java.lang.String;
- import java.util.ArrayList;
- /**
- * Write a description of class Test here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Test
- {
- // instance variables - replace the example below with your own
- private int x;
- private final clNamen sNameHolen;
- private String sNameTest;
- ArrayList<String> sArray;
- /**
- * Constructor for objects of class Test
- */
- public Test(clNamen sName)
- {
- // initialise instance variables
- x = 0;
- this.sNameHolen = sName;
- }
- /**
- * An example of a method - replace this comment with your own
- *
- * @param y a sample parameter for a method
- * @return the sum of x and y
- */
- public int sampleMethod(int y)
- {
- // put your code here
- return x + y;
- }
- public clNamen Fill()
- {
- sArray = new ArrayList<String>();
- System.out.println(sNameHolen);
- // Hier Error
- sArray.add(sNameHolen);
- }
- void DispFill()
- {
- System.out.println(sArray.get(0));
- }
- public clNamen gibName()
- {
- System.out.println(sNameHolen);
- return sNameHolen;
- }
- }