Last active
June 2, 2020 15:49
-
-
Save rajendrauppal/18e3989bf35157ca8045332968bf1b8e to your computer and use it in GitHub Desktop.
Java Bean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
// 1. Implement Serializable interface | |
public class User implements Serializable { | |
// 2. All attributes must be private | |
private int id; | |
private String name; | |
// 3. Should have a no argument public default constructor | |
public User() {} | |
public User(int id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
// 4. Should have public getters and setters for attributes | |
public getId() { return this.id; } | |
public setId(int id) { this.id = id; } | |
public getName() { return this.name; } | |
public setName(String name) { this.name = name; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment