Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Program to illustrate the Concept of Association

// Java Program to illustrate the
// Concept of Association
 
// Importing required classes
import java.io.*;
 
// Class 1
// Bank class
class Bank {
 
    // Attributes 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 {
    // Attributes of employee
    private String name;
    // Employee name
    Employee(String name)
    {
        // This keyword refers to current instance 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 method
    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 :: does not have a NavController set on 21312310 kotlin 
Java :: telegraf-agent-configuration 
Java :: excel data formatter in java 
Java :: java default keyword 
Java :: java access enum per index 
Java :: stacks based on a linked list 
Java :: Calling constructor methods in java 
Java :: at com.rezafirstapp.simplediceroller.MainActivity$2.run(MainActivity.java:56) at java.lang.Thread.run(Thread.java:923) 
Java :: how to show the hex detail of a file in java 
Java :: stop countdown timer when exiting an activity 
Java :: TYPE_INT_ARGB 
Java :: add pd4j to application 
Java :: Java the implements this function will return a copy of the original String that has all characters replaced with plus signs ("+"), with the exception of word string appearances, which are left alone. 
Java :: java spigot string to kyori textcomponent 
Java :: How to code the Fibonacci Sequence using simple iterative loops in java 
Java :: variable for java 
Java :: check if object is a string java 
Java :: Java/Perl - "sprintf function in java" or "string format" 
Java :: domain validation test spring boot 
Java :: java how to make a recrussive boolean function 
Java :: spring data elasticsearch aggregation max 
Java :: java inetaddress workaround how to get localhost secure 
Java :: arraylist character agregar elementos en java 
Java :: Example of ArrayDeque 
Java :: square operator java 
Java :: java list comparator lambda 
Java :: open youtube by default in full screen pragmatically 
Java :: com.google.firebase.database.DatabaseException: Serializing Arrays is not supported, please use Lists instead 
Java :: java try with multiple resources 
Java :: what is method overriding in java 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =