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

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 :: statusbar text color android 
Java :: Count Occurrences in Seven Integers Using Java Single Dimension Arrays 
Java :: java string length validation regex 
Java :: java swing dialog box 
Java :: java binart tree print 
Java :: mockito mock void methods 
Java :: java get number of months between two dates 
Java :: random int in range java 
Java :: Java Writer Using FileWriter 
Java :: simple function java 
Java :: java get month 
Java :: upper en java 
Java :: java get attributes from class 
Java :: java suppresswarnings unchecked 
Java :: I/flutter (10109): {filePath: null, errorMessage: java.io.FileNotFoundException: open failed: EACCES (Permission denied), isSuccess: false} 
Java :: convert char array to set in java 
Java :: java memory increase command 
Java :: how to calculate angle difference 
Java :: Java program to print decimal to octal conversion 
Java :: java write to a file 
Java :: json array get json object 
Java :: declare java class 
Java :: what is lambda expression in java 
Java :: fixed length array powershell 
Java :: rainbow six 
Java :: Java Create an OutputStream 
Java :: spring log info 
Java :: Java print() and println() 
Java :: how to sort arraylist 
Java :: linkedlist java 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =