Skip to content
EntityQ6814247· pop 5· linked from 28 articles

member variable

Sign in to save

Also known as field, field of an object, field of a class, attribute of an object, attribute of a class, class field, data member, data attribute

variable intrinsic to objects in object-oriented programming

Described at

Declaring Member Variables (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

This beginner Java tutorial describes fundamentals of programming in the Java programming language

docs.oracle.com

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Dev.java for updated tutorials taking advantage of the latest releases. See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. The fields of Bicycle are named cadence , gear , and speed and are all of data type integer ( int ). The public keyword identifies these fields as public members, accessible by any object that can access the class. The first (left-most) modifier used lets you control what other classes have access to a member field. For the moment, consider only public and private . Other access modifiers will be discussed later. public modifier—the field is accessible from all classes. private modifier—the field is accessible only within its own class. In the spirit of encapsulation, it is common to make fields private. This means that they can only be directly accessed from the Bicycle class. We still need access to these values, however. This can be done indirectly by adding public methods that obtain the field values for us: All variables must have a type. You can use primitive types such as int , float , boolean , etc. Or you can use reference types, such as strings, arrays, or objects. All variables, whether they are fields, local variables, or parameters, follow the same naming rules and conventions that were covered in the Language Basics lesson, Variables—Naming .

Excerpt from a page describing this subject · 7,906 chars · not written by Vinony

Wikidata facts

Show 1 more fact

via Wikidata · CC0

Available in 5 languages

via Wikidata sitelinks · CC0

Connections

Categories