Item i1 = new CD();
I don't understand how I can instantiate an object from a class and put it in another class? Please explain what do the classes Item and CD refer to?
Item i1 = new CD();
I don't understand how I can instantiate an object from a class and put it in another class? Please explain what do the classes Item and CD refer to?
Presumably, CD either extends Item, or, if Item is an interface, CD implements it.
Item i1 defines variable, and allows it to hold reference to objects of type Item. new CD(); creates object of type CD and returns reference to it which is assigned to variable i1. We can do it when class CD is subtype of class/interface Item.