Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Association in java

(Association)

Association in Java defines the connection between two classes that
are set up through their objects. Association manages one-to-one, 
one-to-many, and many-to-many relationships. In Java, the multiplicity 
between objects is defined by the Association. It shows how objects 
communicate with each other and how they use the functionality and 
services provided by that communicated object.
  
  In Java, two types of Association are possible:

	1) IS-A Association (is also referred to as Inheritance)
	2) HAS-A Association
		a) Aggregation
		b) Composition
Comment

Concept of Association in java

// Java Program to illustrate the
// Concept of Association
 
// Importing required classes
import java.io.*;
 
// Class 1
// Bank class
class Bank {
 
    // Attribures of bank
    private String name;
 
    // Constructor of this class
    Bank(String name)
    {
        // this keyword refers to current instance itself
        this.name = name;
    }
 
    // Method of Bank class
    public String getBankName()
    {
        // Returning name of bank
        return this.name;
    }
}
 
// Class 2
// Employee class
class Employee {
    // Attribures of employee
    private String name;
    // Employee name
    Employee(String name)
    {
        // This keyword refwrs to current insytance itself
        this.name = name;
    }
 
    // Method of Employee class
    public String getEmployeeName()
    {
        // returning the name of employee
        return this.name;
    }
}
 
// Class 3
// Association between both the
// classes in main method
class GFG {
 
    // Main driver mmethod
    public static void main(String[] args)
    {
 
        // Creating objects of bank and Employee class
        Bank bank = new Bank("ICICI");
        Employee emp = new Employee("Ridhi");
 
        // Print and display name and
        // corresponding bank of employee
        System.out.println(emp.getEmployeeName()
                           + " is employee of "
                           + bank.getBankName());
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: check have string have just numbers 
Java :: how to check whether a character is alphabet or not in java 
Java :: java bigdecimal check less zero 
Java :: Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler 
Java :: java image draw 
Java :: java list contains object with property 
Java :: set java home sdk macbook 
Java :: Problem adding rectangle in javaFX 
Java :: android studio constraint layout proportional height 
Java :: string to byte array java 
Java :: literals in java 
Java :: java variable in string 
Java :: java read directory 
Java :: open camera or gallery on button click android 
Java :: java stream distinct by object atribute 
Java :: how to resize image in java swing 
Java :: jbutton close jframe java 
Java :: check palindrome in java 
Java :: implementing iterator for linked list java 
Java :: android imageview set image from drawable programmatically 
Java :: get request in java 
Java :: how to initialize array in java 
Java :: ternary operator in java for null check 
Java :: sort an int array java 
Java :: android ask if system is in dark mode 
Java :: how to make a loop in java 
Java :: enum set in java 
Java :: formatting an integer in java 
Java :: java clone matrix 
Java :: each character in string java 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =