public class User { private String name; // Constructor public User(String name) { this.name = name; } // Getter and Setter methods public String getName() { return name; } public void setName(String name) { this.name = name; } } // Setting name of User object User newUser = new User("John"); newUser.setName("Jane");In the above example, we have created a User class with a private name field and have provided getter and setter methods for the name field. The setName method is used to set the name of the User object. The package library for setName method is available in the Java standard library under the java.lang package.