waltermilner

Untitled

May 1st, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. class B {} // some class
  2.  
  3. class A
  4. {
  5.   B b = new B(); // composition - every A instance contains a B object
  6.  
  7.   void someMethod()
  8.   {
  9.     B c = new B();
  10.     // not composition - it is a local variable
  11.     // a B object is temporarily constructed on the stack when this method executes
  12.     // and ends when this method ends.
  13.     // It is not part of an A object
  14.    
  15.   }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment