1

Java_Composition: A class can have references to objects of other classes as members.

Question?: Should that be a Instance-variable of a class to call it as Composition Or it is also called as Composition, if it is a Local-variable ?

Demo: Preceding question for local reference-type variables at lines 5 and 6.

1   public class EmployeeTest
2   {
3   public static void main(String[] args)
4   {
5     Date birthday;
6     Date birth = new Date(12, 12, 1950);
7   }
8   } 
cenk
  • 51
  • 3

1 Answers1

1

Should that be a Instance-variable of a class to call it as Composition Or it is also called as Composition, if it is a Local-variable?

Not really, remember Composition is also known as HAS-A relationship,

so ask yourself the question:

EmployeeTest has a date?

the answer is NO, the date is only scoped in a method and nowhere else...

so that is not Composition.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97