Im kind of new to java and im struggling very hard at this one. I just want to make a syso with the age and name of Stefan
public class Person {
public int alter;
public String placeofbirth;
public Person(int alter, String placeofbirth) {
this.alter = alter;
this.placeofbirth = placeofbirth;
}
Person stefan = new Person(19, "Berlin");
public String toString() {
return "test" + stefan;
}
public static void main(String[] args) {
System.out.println(stefan);
}
}
What am i doing wrong?
Would be very grateful to get help
@Overridetag only produces an error when the method doesn't actually overrides a method, it's not necessary but very useful.Personinto themainmethod.toString()ofPersonwould create an awfulStackOverflowErrorbecause it's a recursive method. Change it topublic String toString(){ return "test "+alter+" "+placeofbirth;}. Also the Personstefanisn't in the scope of the main method.