User.java
unknown
java
7 months ago
1.8 kB
6
Indexable
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.encap;
/* How to achieve full encapsualated class:
Data hiding - Making all the data members private
Data validation - Setter and getter to set and get the data
Constructor
*/
public class User {
private static int nextId = 2025001;
private int id;
private String firstName;
private String lastName;
private int age;
private String userName;
private String password;
// Mutator Method / Setter Method
public void setId(int id) {
// private field = paramater
this.id = id;
nextId++;
}
// Accessor Method // Getter Method
public int getId() {
return id;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public void setUserName(String userName){
this.userName = userName;
}
public String getUserName(){
return userName;
}
public void setPassword(String password){
this.password = password;
}
public String getPassword() {
return password;
}
}
// syntax
// 2024001
// this -> immediately refer to the object
// conventional
// unconventional
Editor is loading...
Leave a Comment