English

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.

  1. Objects as attributes help in establishing relationships between different classes.
  2. They allow one class to use the properties and methods of another class.
  3. They promote code reusability, modularity and better organization of programs.
  4. 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?
Chapter 4: Objects - EXERCISE [Page 107]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 4 Objects
EXERCISE | Q 3. | Page 107
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×