Question #248250

Explain static variable, object variable, instance variable with example


Expert's answer

Static variable is a variable  that is declared with the static keyword in a class, but outside a method, constructor or a block.

Example of static variable is:

static int count=0;

An object variable is a container that holds a reference to a specific instance of a class.

Example of object variable is:

int x;

Instance variable are non-static variables which are defined in a class outside any method, constructor or a block. They belong to a class.

Example of instance variable:

public String pageName;


LATEST TUTORIALS
APPROVED BY CLIENTS