SlideShare uma empresa Scribd logo
1 de 19
Without using the inheritance, Is it
possible to inherit the property of
another class?
How??
Using
Association
Relationship Between Classes
Inheritance
• Is-A
• extends
• Blood relation
• Tightly coupled
Association
• Is-A
• Reference variable, new
• No Blood relation
• Not Tightly coupled
• Association establishes a relationship between any two objects.
• Objects have an independent lifecycle i.e.) no ownership between the
objects.
Association
Association
Prime
Minister
Minister-1
Minister-2
Minister-n
Defense
Finance
External
Affairs
Internal
Affairs
More…
People
Country
Association
Aggregation
Composition
Association
Association
CAR
Music_Player Engine
Aggregation Composition
Association
University
Anna University VIT University
Is-A Is-A
Professor
[Weak]
Branches
(Mech, EEE, CSE)
[Strong]
Has-A Has-A
// Predict the output
import java.util.*;
class Company
{
private String name;
Company(String name) {
this.name = name;
}
public String getCompanyName() {
return this.name;
}
}
class Employee
{
private String name;
Employee(String name){
this.name = name;
}
public String getEmployeeName() {
return this.name;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Association
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
String c_name = sc.next();
String e_name = sc.next();
Company c = new Company(c_name);
Employee emp = new Employee(e_name);
System.out.println(emp.getEmployeeName() + " is employee of " +
c.getCompanyName());
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Composition
 It represents part – of relationship
 Both classes are highly dependent on each other
 Example:
Every human has a heart (part - of relationship)
Human and heart(Dependent on each other)
Books and Authors(Dependent on each other)
// Predict the output
class Book{
String author;
String title;
Book(String author, String title){
this.author = author;
this.title = title;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Library {
Book book;
Library(Book book){
this.book = book;
}
public static void main(String[] args) {
Book b = new Book("Shakespeare", "Julius caesar" );
Library library = new Library(b);
System.out.println(library.book.author);
System.out.println(library.book.title);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Predict the output
class Address
{
private int doorNo;
private String rem;
public int getDoorNo(){
return doorNo;
}
public void setDoorNo(int doorNo){
this.doorNo = doorNo;
}
public String getRem(){
return rem;
}
public void setRem(String rem){
this.rem = rem;
}
public String toString(){
return " Address: " + doorNo + " ," + rem;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Person
{
private String Name;
private Address address;
public Person()
{
address = new Address();
}
public void setName(String Name)
{
this.Name = Name;
}
public Address getAddress()
{
return address;
}
public String toString()
{
return "Person Name: " + Name + address ;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String args[]) {
Person person = new Person();
person.setName("Mahendra Singh Dhoni");
person.getAddress().setDoorNo(07);
person.getAddress().setRem("XXX, Ranchi, Jharkhand.");
System.out.println(person);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String args[]) {
Person person = new Person();
person.setName("Mahendra Singh Dhoni");
person.getAddress().setDoorNo(07);
person.getAddress().setRem("XXX, Ranchi, Jharkhand.");
System.out.println(person);
person = null;
if(person != null)
{
System.out.println(person.getAddress());
}
else
System.out.println("Address Does not Exist");
}
}
// Predict the output
class Engine {
public String toString() {
return "L-twin cylinder Engine";
}
}
class Bike {
String name;
private Engine engine;
public Bike(String name, Engine engine){
this.name=name;
this.engine = engine;
}
public Engine getEngine() {
return engine;
}
public void setEngine(Engine engine) {
this.engine = engine;
}
public String toString() {
return name + " Bike " + "uses " + engine; }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String[] args) {
Engine engine = new Engine();
Bike bike = new Bike(“Ducati",engine);
System.out.println(engine);
System.out.println(bike);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Main {
public static void main(String[] args) {
Engine engine = new Engine();
Bike bike = new Bike(“Ducati",engine);
bike = null;
System.out.println(engine);
System.out.println(bike);
}
}
THANK YOU

Mais conteúdo relacionado

Semelhante a WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15_Association.pptx

Kotlin Data Model
Kotlin Data ModelKotlin Data Model
Kotlin Data ModelKros Huang
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simpleleonsabr
 
11slide
11slide11slide
11slideIIUM
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfarishmarketing21
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in javaHarish Gyanani
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Add a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdfAdd a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdfSebastianRzuHarrisw
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesNebojša Vukšić
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritanceshatha00
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfShaiAlmog1
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Gouda Mando
 
About java
About javaAbout java
About javaJay Xu
 

Semelhante a WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15_Association.pptx (20)

Kotlin Data Model
Kotlin Data ModelKotlin Data Model
Kotlin Data Model
 
F# for C# Programmers
F# for C# ProgrammersF# for C# Programmers
F# for C# Programmers
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simple
 
11slide
11slide11slide
11slide
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
Simple class and object examples in java
Simple class and object examples in javaSimple class and object examples in java
Simple class and object examples in java
 
Groovy
GroovyGroovy
Groovy
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Add a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdfAdd a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdf
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examples
 
Kotlin class
Kotlin classKotlin class
Kotlin class
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
Initial Java Core Concept
Initial Java Core ConceptInitial Java Core Concept
Initial Java Core Concept
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"
 
About java
About javaAbout java
About java
 

Mais de MaruMengesha

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...MaruMengesha
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...MaruMengesha
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookMaruMengesha
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation AssignmentMaruMengesha
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookMaruMengesha
 

Mais de MaruMengesha (13)

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_22-Feb-2021_L9-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_11-Feb-2021_L5-...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_10-Feb-2021_L4_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Feb-2021_L2_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Mar-2021_L13...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_03-Feb-2021_L1_...
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_01-Mar-2021_L12...
 
Chemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text bookChemistry Student G9.pdf chemistry text book
Chemistry Student G9.pdf chemistry text book
 
eco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignmenteco ppt.pptx Economics presentation Assignment
eco ppt.pptx Economics presentation Assignment
 
G12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text bookG12-Agriculture-STB-2023-web.pdf Agriculture text book
G12-Agriculture-STB-2023-web.pdf Agriculture text book
 

Último

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Último (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15_Association.pptx

  • 1.
  • 2. Without using the inheritance, Is it possible to inherit the property of another class? How?? Using Association
  • 3. Relationship Between Classes Inheritance • Is-A • extends • Blood relation • Tightly coupled Association • Is-A • Reference variable, new • No Blood relation • Not Tightly coupled
  • 4. • Association establishes a relationship between any two objects. • Objects have an independent lifecycle i.e.) no ownership between the objects. Association
  • 8. Association University Anna University VIT University Is-A Is-A Professor [Weak] Branches (Mech, EEE, CSE) [Strong] Has-A Has-A
  • 9. // Predict the output import java.util.*; class Company { private String name; Company(String name) { this.name = name; } public String getCompanyName() { return this.name; } } class Employee { private String name; Employee(String name){ this.name = name; } public String getEmployeeName() { return this.name; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 10. public class Association { public static void main (String[] args) { Scanner sc = new Scanner(System.in); String c_name = sc.next(); String e_name = sc.next(); Company c = new Company(c_name); Employee emp = new Employee(e_name); System.out.println(emp.getEmployeeName() + " is employee of " + c.getCompanyName()); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 11. Composition  It represents part – of relationship  Both classes are highly dependent on each other  Example: Every human has a heart (part - of relationship) Human and heart(Dependent on each other) Books and Authors(Dependent on each other)
  • 12. // Predict the output class Book{ String author; String title; Book(String author, String title){ this.author = author; this.title = title; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 13. public class Library { Book book; Library(Book book){ this.book = book; } public static void main(String[] args) { Book b = new Book("Shakespeare", "Julius caesar" ); Library library = new Library(b); System.out.println(library.book.author); System.out.println(library.book.title); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 14. // Predict the output class Address { private int doorNo; private String rem; public int getDoorNo(){ return doorNo; } public void setDoorNo(int doorNo){ this.doorNo = doorNo; } public String getRem(){ return rem; } public void setRem(String rem){ this.rem = rem; } public String toString(){ return " Address: " + doorNo + " ," + rem; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 15. class Person { private String Name; private Address address; public Person() { address = new Address(); } public void setName(String Name) { this.Name = Name; } public Address getAddress() { return address; } public String toString() { return "Person Name: " + Name + address ; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 16. public class Main { public static void main(String args[]) { Person person = new Person(); person.setName("Mahendra Singh Dhoni"); person.getAddress().setDoorNo(07); person.getAddress().setRem("XXX, Ranchi, Jharkhand."); System.out.println(person); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class Main { public static void main(String args[]) { Person person = new Person(); person.setName("Mahendra Singh Dhoni"); person.getAddress().setDoorNo(07); person.getAddress().setRem("XXX, Ranchi, Jharkhand."); System.out.println(person); person = null; if(person != null) { System.out.println(person.getAddress()); } else System.out.println("Address Does not Exist"); } }
  • 17. // Predict the output class Engine { public String toString() { return "L-twin cylinder Engine"; } } class Bike { String name; private Engine engine; public Bike(String name, Engine engine){ this.name=name; this.engine = engine; } public Engine getEngine() { return engine; } public void setEngine(Engine engine) { this.engine = engine; } public String toString() { return name + " Bike " + "uses " + engine; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 18. public class Main { public static void main(String[] args) { Engine engine = new Engine(); Bike bike = new Bike(“Ducati",engine); System.out.println(engine); System.out.println(bike); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public class Main { public static void main(String[] args) { Engine engine = new Engine(); Bike bike = new Bike(“Ducati",engine); bike = null; System.out.println(engine); System.out.println(bike); } }

Notas do Editor

  1. 1st slide (Mandatory)
  2. Explanation for 1st point: The relation between object be like one to one, many-to-one, one-to-many and many-to-many. Example: A country has one prime minister(one to one) Prime minister has different minister under his control (one to many) All minister governs the people (many to many) Explanation for 2nd point: Both the objects can be create and delete independently. Relation between teacher and student. If a teacher left the school we don’t need to delete student and vice versa. Both has independent function.
  3. A country has one prime minister(one to one) Prime minister has different minister under his control (one to many) All minister serves for the welfare of the people (many to many) There is no ownership between these object Example : If a prime minister dies whether the minister or people are dying? Ans: no If the people are dying whether the minister or prime minister are dying along with them? Ans: no So this example shows association between these classes
  4. In Association, Aggregation and composition are two forms. Aggregation is a weak bond between two classes. Compostion is a strong bond between two classes.
  5. Description: Car
  6. Input: Face Kirthiga Mohan Kirthiga Mohan is employee of Face. Description: Here the class company and employee are two different class are associated through objects. Company can have many employees, So it is a one-to-many relationship.
  7. Output: Shakespeare Julius caesar So, If Library gets destroyed then All books within that particular library will be destroyed. i.e. book can not exist without library. That’s why it is composition.
  8. Explanation for this Slide: I have created a class name called Address. In Address class I have created the object of Address i.e.) doorNo & rem(street name, city, state) Then I am getting the value of the object using getters and setters method.
  9. Explanation for this Slide: Here I have a created class called Person , In person class I am composing the Address class by calling constructed method. Public Person() { address = new Address; } Creating a object for address in person class this compose the property of address in person class. Then, I am getting person name ,person address using getter method and setter method.
  10. Output: Person Name: Mahendra Singh Dhoni Address: 7 ,XXX, Ranchi, Jharkhand. // 1st Output. Address does not exist //2nd Output Explanation: I am creating a object for Person class. Then I am passing the value for person and address. It will print the 1st Output. When I delete the person class. The address class also deleted. This shows that one class is dependent on others. It will print the 2nd Output.
  11. Output: L-twin cylinder Engine //1st Output Ducati Bike uses L-twin cylinder Engine L-twin cylinder Engine //2nd Output Null Explanation: Engine engine = new Engine() creates a new Engine object i.e.) L-twin cylinder Engine, we are creating it outside bike. We are creating a bike using new Bike(“Ducati”,engine);  i.e. passing the bike name & outside engine object to Bike constructor. After that we are printing   engine  and bike.getEngine(). Now, it will print L-twin cylinder Engine Ducati Bike uses L-twin cylinder Engine Now after setting bike = null;  we are printing engine. It still gives same result i.e.) L-twin cylinder Engine It means even after we have destroyed bike, its engine still exists. Even, tough the engine exist but there is a strong bond between bike and engine. We are printing bike. It print NULL. Note: stringto( ) method is used to return the String.
  12. Thank you slide