Java language convention; getters/setters

Posted by Skogen on Stack Overflow See other posts from Stack Overflow or by Skogen
Published on 2010-05-19T11:39:00Z Indexed on 2010/05/19 11:40 UTC
Read the original article Hit count: 257

Filed under:
Public class Example {

    private int number;

    public Example(int number){
        this.number = number;
    }

    public int getNumber(){
        return number;
    }

    public void setNumber(int number){
        this.number = number;
    }

    public static void main(String[] args){
        Example e = new Example(5);

What is preffered when accessing a variable within its own class; "e.number" or "e.getNumber()" ?

© Stack Overflow or respective owner

Related posts about java