Controlling Access to Members of a Class - Java Object Oriented Design

Java examples for Object Oriented Design:Access Level

Introduction

Create private instance members rather than public or protected.

Demo Code

class Player {/* w  ww. ja  v a 2s.  c  om*/
   
    private String firstName = null;
    private String lastName = null;
    private String position = null;
    private int status = -1;
    
    public Player(){
        
    }
    
    public Player(String position, int status){
        this.position = position;
        this.status = status;
    }

}

Related Tutorials