An attribute is a property of an entity (entity such as class etc)
Attributes are variables or identifiers but are bound to an entity
An Attribute can store some value like number or string, or can be a reference to a object
Consider following Html Button element
<button class="btn btn-primary" id="btn1" style="width:20mm; height:5mm;">Submit</button>
Here, class
id
and style
are attributes of button
element
Consider, following java class
public class Person {
String name = "John";
final static String SPECIES = "Human";
public static void main(String[] args) {
Person person_object = new Person();
System.out.println(String.format("%s is a %s", person_object.name, Person.SPECIES));
}
}
Here, name and SPECIES are attributes of Person class, which can be accessed by its object person_object
SPECIES
is a constant which is same for all objects of class Person
, while name is a variable