मराठी

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.

  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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Objects - EXERCISE [पृष्ठ १०७]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 4 Objects
EXERCISE | Q 3. | पृष्ठ १०७
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×