public class Adhar {
private long adharno;
public Adhar(long adharno) {
this.adharno = adharno;
}
@Override
public String toString() {
return "Adhar [adharno=" + adharno + "]";
}
boolean dob()
{
System.out.println("this displys the dob");
return true;
}
}
public class Mobilenumber {
private long airtelno;
private long jiono;
public Mobilenumber(long airtelno, long jiono) {
this.airtelno = airtelno;
this.jiono = jiono;
}
@Override
public String toString() {
return "Mobilenumber [airtelno=" + airtelno + ", jiono=" + jiono + "]";
}
boolean electionid()
{
System.out.println("this displays the electionid");
return true;
}
}
public class Person {
private String name;
Adhar a1;
Mobilenumber m;
@Override
public String toString() {
return "Person [name=" + name + ", a1=" + a1 + "]";
}
public Person(String name,Mobilenumber m,long adharno)
{
this.name=name;
this.m=m;
this.a1 = new Adhar(adharno);
}
}
public class aggmain {
public static void main(String[] args) {
//a2 object only used for association
Adhar a2=new Adhar(564512348910l);
Mobilenumber m1=new Mobilenumber(987654321l,9786561111l);
Person p1=new Person("name1",m1,564512348910l);//adhar-composition
//m1-aggregation
System.out.println(m1);
//association
boolean x=a2.dob();
boolean y=m1.electionid();
System.out.printf("%s and %s",x,y);
/*
* composition:
* here adhar class is called inside the person class,so the
* parameter passed through person object
* aggregation:
* here mobile number class object is created separately and called in the person class
* so when person class is null mobile class is still existed
* Association:
* here two method are created one in adhar class and another in mobile number class
* if we have to display together we need to call with corresponding object in the print statement
*/
*/
}
}