Skip to content

Instantly share code, notes, and snippets.

@SamuelSchwent
Created March 3, 2016 15:10
Show Gist options
  • Select an option

  • Save SamuelSchwent/eb678248ff8826364837 to your computer and use it in GitHub Desktop.

Select an option

Save SamuelSchwent/eb678248ff8826364837 to your computer and use it in GitHub Desktop.
Java - Aggregation Example
package Challenge2;
public class DisplayInventoryItem {
public static void main(String[] args) {
String description = "This is a large Bolt.";
double units = 13;
InventoryItem item1 = new InventoryItem(description, units);
InventoryItem item2 = new InventoryItem(item1);
System.out.println("Item 1 Units: " + item1.units);
System.out.println(item1.description);
System.out.println("Item 2 Units: " + item2.units);
System.out.println(item2.description);
}
}
package Challenge2;
public class InventoryItem {
String description;
Double units;
public InventoryItem(String description, double units)
{
this.description = description;
this.units = units;
}
public InventoryItem(InventoryItem item)
{
description = item.description;
units = item.units;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment