How do you rate Objects as Attributes?
Advertisements
प्रश्न
How do you rate Objects as Attributes?
दीर्घउत्तर
Advertisements
उत्तर
In Java, an object can be used as an attribute of another class. This means that a class can contain an object of another class as one of its data members. Such attributes are called reference variables because they refer to objects.
- Objects as attributes help in establishing relationships between different classes.
- They allow one class to use the properties and methods of another class.
- They promote code reusability, modularity and better organization of programs.
- They are useful for representing complex real-world entities.
Example:
class Address
{
String city = "Mumbai";
}
class Student
{
Address addr = new Address();
}
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
