I read that to get length of an array, I use the length
attribute, like arrayName.length
. What is an attribute? Is it a class?
10.2 Attributes Variables that belong to an object are usually called attributes, but you might also see them called “fields”. To access an attribute of an object, Java uses dot notation. For example: int x = blank.
Any variable that is bound in a class is a class attribute . Any function defined within a class is a method . Methods receive an instance of the class, conventionally called self , as the first argument.
Attributes in object-oriented programming are defined for classes and objects such as a data element representing the quality or state of the class or object. An attribute defines a particular property of an object, element or file. It can also refer to a specific value for a given instance of that property.
Attributes are refering to additional information of an object. Properties are describing the characteristics of an object.
An attribute is another term for a field. It's typically a public constant or a public variable that can be accessed directly. In this particular case, the array in Java is actually an object and you are accessing the public constant value that represents the length of the array.
A class is an element in object oriented programming that aggregates attributes(fields) - which can be public accessible or not - and methods(functions) - which also can be public or private and usually writes/reads those attributes.
so you can have a class like Array
with a public attribute length
and a public method sort()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With