Java ClassesLesson 27Free preview
Java Class Attributes
This lesson is part of Java · All levels
Summary
A class attribute or field is a variable that a class has to store its data. There's a field instance where the values of each object are different, and there's a static field that all objects share. The value of the field can be filled directly, via the constructor, or via the method setter.
Key points
- The instance variable is owned by each object and its value can vary.
- The static field is owned by the class so it applies to all objects
- The final modifier makes the value of an attribute unchangeable after initialization
- Attributes can be assigned values when declared, in constructors, or by methods.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.