0
public class Person {
   String name;

   public Person(String name){
   }

   public String getName() {
       return name;
   }
}

public class Main{
    public static void main(String[] args) {
        Index index = new Index();
        Person person = new Person("Paul");
        index.addPerson(person);
    }
}

public class Index{
    public void addPerson(Person person){
        System.out.println(person.toString());
        System.out.print(" - " + person.getName());
    }
}

Prints: "[ProjectPath]Person@1431340 - null"

Why doesn't it print "Paul" and how to fix that?

Thank you.

Nik
  • 179
  • 1
  • 3
  • 11

0 Answers0