Home > Software engineering >  Is the correct terminology in Java attributes or class variables or class fields etc? Many thanks [d
Is the correct terminology in Java attributes or class variables or class fields etc? Many thanks [d

Time:09-17

Is the correct terminology in Java attributes or class variables or class fields etc? Many thanks

This to confirm is for variables declared in the class Main...I've seen these variables called a few things and just curious what the correct term for Java would be?

e.g.

public class Main {
            int x = 10;
            int modelYValue;
            String modelName;
            Boolean joyous;
            private int age = 28;
            }

CodePudding user response:

Those are instance members, or instance variables. When you create an object those members get created as part of it. Each object has its own instance member variables. See https://en.m.wikipedia.org/wiki/Instance_variable

Class member means the variables belong to the class, not to any object instance. Static variables are class members.

People tend to confuse these and say class member when they mean instance member.

  • Related