Ad
  • Custom User Avatar

    Very confusing. You create a Person class with a name property, and then declare a greet method... if this were proper OOP, the greet method assigned to the person would greet somebody else. Instead, the code expects YOU to greet the person. This would better be represented as a function that takes in a Person to greet, for example:

    public class Person {
        String name;
    
        public Person(String name) {
            this.name = name
        }
    
        public String greet(Person personToGreet) {
            System.out.println("Hello %s, my name is %s", personToGreet.name, this.name);
        }
    }