Instance Variables is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Instance Variables
| Also Known As | Number of Instance Variables (NIV) |
| API ID | CountDeclInstanceVariable |
| Targets | Architectures Classes Files Project |
| Languages | Basic C# C++ Java Pascal Python Web |
| Categories | Object Oriented Variable Counts |
| Cost | Query |
| Suites | Lorenz & Kidd |
Number of instance variables.
Variables defined in a class that are only accessible through an object of that class.
For example:
class BoatCar: private Car, public Boat, protected DualPurpose {
public:
// Public Instance Function
BoatCar() : Car(4), Boat(), mInWater(false), mColor("Blue") {}
virtual int passengers() const { return 4; }
static int numRegistered() { return sRegistered; }
bool mInWater; // Public Instance Variable
protected:
void toggleInWater(bool inWater) { mInWater = inWater; }
char * mColor; // Protected Instance Variable
friend void init() {}
static int sRegistered;
static double calcSpeed(double distance, double time) {
return distance/time;
}
private:
int mMaxPassengers;
void travel() {}
};
BoatCar declares three instance variables across all access levels — mInWater (public), mColor (protected), and mMaxPassengers (private) — so CountDeclInstanceVariable = 3.
See Public Instance Variables, Protected Instance Variables, and Private Instance Variables for the breakdown by access level, and Class Variables for the static counterpart. C# also has additional access levels: see Internal Instance Variables and Protected Internal Instance Variables.
Also known as Lorenz & Kidd - Number of Instance Variables (NIV).
- Basic: Project, Class, Struct
- C#: Project, Class, Struct
- C++: Project, Class, Struct, Union
- Java: Project, File, Class, Interface
- Pascal: Project, Class, Interface
- Python: Project, Class
- Web: Project, PHP Class, PHP Interface