How do you rate Objects as Attributes?
Advertisements
Question
How do you rate Objects as Attributes?
Long Answer
Advertisements
Solution
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
Is there an error in this question or solution?
