--

Yes, Its correct. but in case instead of Boolean if we want to return Object then we need to write like this.

public Employee getValidEmployee(String userName) {

if (userName != null && userName.equals("Tom")) {

return new Employee("sumit","singh",15,1000);

}

return null;

}

--

--

Gain Java Knowledge
Gain Java Knowledge

Written by Gain Java Knowledge

The Java programming language is one of the most popular languages today. Stay up to date with news, certifications, free learning resources and much more.

Responses (1)