Friday , April 28 2017
Home / java / OOPS / What is Association in Java

What is Association in Java

Object is the real world entity like pen, table and many more so the Object-Oriented Programming is the paradigm or methodology for designing the program using the objects and classes. OOPS simplifies all software development along with maintenance of the concepts such as Object, Class, Inheritance and many more. Aggregation is the type of association and it is the relationship in between the two classes such as the association but it is also directional association. The directional association is strictly the one way association so it represents the Has-A relationship. Consider two classes Student as well as Address class and each of the students will have the address with relationship between the student and address. Consider it vice versa so the Address with the easy managing of the codes. OOPs also provides the data hiding and the Procedure-oriented programming language can also be accessed efficiently anywhere. OOPs provide the ability for simulating the real-world event effectively. The relationship between the classes is significant so the building blocks of the object oriented programming basics like:


Association establish relationship between any two objects. It can be defined as the multiplicity between any objects so you must know about the one-to-one, many-to-one, one-to-many and many-to-many as all these are the association between objects. Association also has its special form with Aggregation and Composition is the special form of aggregation.

For Example: Organization and Employee have an association.


 * @author chandrashekhar
public class AssociationDemo {

    public static void main(String[] args) {
        Organization organization = new Organization();
        Employee employee = new Employee();
        System.out.println(employee.getEmployeeName()+" is an Employee of "+


class Organization {

    private String organizationName;

    public String getOrganizationName() {
        return organizationName;

    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;


class Employee {

    private String employeeName;

    public String getEmployeeName() {
        return employeeName;

    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;


Output: Rahul is an Employee of Google

In the above example one Organization has many number of Employees. There fore Organization and Employee relationship is one to many. And also those two are two different entities. There fore the relationship between the two entities is called association.

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Check Also

Java access modifiers

  Java access modifiers determines a particular class can access the data members or methods. …

Leave a Reply

Your email address will not be published. Required fields are marked *