-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_Aggregation Ex.1
More file actions
36 lines (31 loc) · 828 Bytes
/
Copy path3_Aggregation Ex.1
File metadata and controls
36 lines (31 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
class Address
{
int streetNum;
String city;
Address(int street, String c)
{
this.streetNum = street;
this.city = c;
}
}
class StudentClass
{
int rollNum;
String studentName;
//Creating HAS-A relationship with Address class
Address studentAddr;
StudentClass(int roll, String name, Address addr)
{
this.rollNum = roll;
this.studentName = name;
this.studentAddr = addr;
}
public static void main(String args[])
{
Address ad = new Address(55, "Agra");
StudentClass obj = new StudentClass(123, "Chaitanya", ad);
System.out.println(obj.rollNum + " " + obj.studentName);
System.out.println("Address: " + obj.studentAddr.streetNum + " " + obj.studentAddr.city);
}
}