Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

instance field java

An instance field, or field, is a variable that's bound to the object itself. 
I can use it in the object without the need to use accessors, and any method 
contained within the object may use it.

If I wanted to use it outside of the object, and it was not public, I would 
have to use getters and/or setters.

public class Point {
    private int xValue; // xValue is a field

    public void showX() {
        System.out.println("X is: " + xValue);
    }
}
 
PREVIOUS NEXT
Tagged: #instance #field #java
ADD COMMENT
Topic
Name
5+7 =