Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an attribute in Java?

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?

like image 544
Naman Avatar asked Dec 12 '11 18:12

Naman


People also ask

What is attribute in Java example?

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.

What is an attribute in a class?

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.

What is an attribute in oops?

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.

What are attributes and properties in Java?

Attributes are refering to additional information of an object. Properties are describing the characteristics of an object.


2 Answers

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.

like image 180
Thomas Owens Avatar answered Sep 28 '22 04:09

Thomas Owens


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 lengthand a public method sort().

like image 28
JSeven Avatar answered Sep 28 '22 04:09

JSeven