BlueJ Übergabe

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • BlueJ Übergabe

    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 ?

    Quellcode

    1. /**
    2. * Write a description of class clNamen here.
    3. *
    4. * @author (your name)
    5. * @version (a version number or a date)
    6. */
    7. public class clNamen
    8. {
    9. // instance variables - replace the example below with your own
    10. private int x;
    11. private final String sName;
    12. private final String sVorname;
    13. /**
    14. * Constructor for objects of class clNamen
    15. */
    16. public clNamen(String sName, String sVorname)
    17. {
    18. // initialise instance variables
    19. x = 0;
    20. this.sName = sName;
    21. this.sVorname = sVorname;
    22. }
    23. /**
    24. * An example of a method - replace this comment with your own
    25. *
    26. * @param y a sample parameter for a method
    27. * @return the sum of x and y
    28. */
    29. public int sampleMethod(int y)
    30. {
    31. // put your code here
    32. return x + y;
    33. }
    34. public String gibName()
    35. {
    36. return sName;
    37. }
    38. }
    Alles anzeigen


    Quellcode

    1. import java.lang.String;
    2. import java.util.ArrayList;
    3. /**
    4. * Write a description of class Test here.
    5. *
    6. * @author (your name)
    7. * @version (a version number or a date)
    8. */
    9. public class Test
    10. {
    11. // instance variables - replace the example below with your own
    12. private int x;
    13. private final clNamen sNameHolen;
    14. private String sNameTest;
    15. ArrayList<String> sArray;
    16. /**
    17. * Constructor for objects of class Test
    18. */
    19. public Test(clNamen sName)
    20. {
    21. // initialise instance variables
    22. x = 0;
    23. this.sNameHolen = sName;
    24. }
    25. /**
    26. * An example of a method - replace this comment with your own
    27. *
    28. * @param y a sample parameter for a method
    29. * @return the sum of x and y
    30. */
    31. public int sampleMethod(int y)
    32. {
    33. // put your code here
    34. return x + y;
    35. }
    36. public clNamen Fill()
    37. {
    38. sArray = new ArrayList<String>();
    39. System.out.println(sNameHolen);
    40. // Hier Error
    41. sArray.add(sNameHolen);
    42. }
    43. void DispFill()
    44. {
    45. System.out.println(sArray.get(0));
    46. }
    47. public clNamen gibName()
    48. {
    49. System.out.println(sNameHolen);
    50. return sNameHolen;
    51. }
    52. }
    Alles anzeigen