Initializing and accessing class member in a greeting method

Report a typo

You are given a class, `Person`, with a member `name` and a method `greet()`. The `greet()` function returns a greeting message that includes the `name` of the `Person`. However, the `name` must be assigned to an object when this object is created. Fill the blanks in the code to ensure that an instance of the `Person` class can be initiated with a `name`, and that this `name` can be correctly accessed in the `greet()` method.

Fill in the gaps with the relevant elements
 class Person {
     String name;
    public Person(String name) {
        .name = name;
    }
    public String greet() {
        return "Hello, my name is " + name;
    }
}
thisprivatepublic

Create a free account to access the full topic