[Solved] greet function does not return string value? [closed]


Your code seems fine..

public class Person {
    String name;

    public Person(String personName) {
        name = personName;
    }

    public String greet(String yourName) {
        return String.format("Hi %s, my name is %s", yourName, name);
    }

    public static void main(String [] args)
    {
        Person p = new Person("Marcx");  // create an object Person
        System.out.println(p.greet("Ankit hacker")); //print the greet message
    }
}

Will output: Hi Marcx, my name is Ankit hacker

So probably you are calling it in the wrong way

EDIT

As Tom precised in the comment, you probably want to change the order of name and yourName

2

solved greet function does not return string value? [closed]