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?

- 30,738
- 21
- 105
- 131

- 2,363
- 5
- 26
- 27
-
Are you sure you're not thinking of Javascript? – James Clark Dec 12 '11 at 18:29
11 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.

- 114,398
- 98
- 311
- 431
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()
.

- 625
- 1
- 6
- 12
-
It's a good example, except in Java arrays aren't instances of `Array`, and there's no `addElement` method on arrays. Arrays in Java are instances of an internal class, which exposes a constant `length` field. – Jonathan Dec 12 '11 at 18:47
-
Yes, that's true. I just picked the first thing that crossed my mind on the method example. But I wasn't trying to be that accurate, maybe I should though. – JSeven Dec 12 '11 at 18:49
-
@JSeven the example is good, but if you could edit your answer to provide a more accurate one it would be better. :) – ahsteele Dec 12 '11 at 19:15
Attribute is a public variable inside the class/object. length attribute is a variable of int type.

- 1
- 1

- 15,341
- 5
- 46
- 64
Attributes is same term used alternativly for properties or fields or data members or class members.

- 436
- 1
- 5
- 14
Attributes are also data members and properties of a class. They are Variables declared inside class.

- 1,215
- 3
- 15
- 26
A class contains data field descriptions (or properties, fields, data members, attributes), i.e., field types and names, that will be associated with either per-instance or per-class state variables at program run time.

- 2,069
- 4
- 21
- 30
An abstract class is a type of class that can only be used as a base class for another class; such thus cannot be instantiated. To make a class abstract, the keyword abstract is used. Abstract classes may have one or more abstract methods that only have a header line (no method body). The method header line ends with a semicolon (;). Any class that is derived from the base class can define the method body in a way that is consistent with the header line using all the designated parameters and returning the correct data type (if the return type is not void). An abstract method acts as a place holder; all derived classes are expected to override and complete the method.
Example in Java
abstract public class Shape
{
double area;
public abstract double getArea();
}
■ What is an attribute?
– A variable that belongs to an object.Attributes is same term used alternatively for properties or fields or data members or class members
■ How else can it be called?
– field or instance variable
■ How do you create one? What is the syntax?
– You need to declare attributes at the beginning of the class definition, outside of any method. The syntax is the following: ;

- 57
- 1
- 6