Page 1 of 1

Assume you have the following two classes: public class Bag { private String name; public Bag() { name = "Fancy bag"; }

Posted: Fri Jul 08, 2022 6:43 am
by answerhappygod
Assume You Have The Following Two Classes Public Class Bag Private String Name Public Bag Name Fancy Bag 1
Assume You Have The Following Two Classes Public Class Bag Private String Name Public Bag Name Fancy Bag 1 (89.48 KiB) Viewed 36 times
Assume you have the following two classes: public class Bag { private String name; public Bag() { name = "Fancy bag"; } } public class Backpack extends Bag { private int noCompartments; // number of compartments in a backpack public Backpack() { noCompartments = 1; } public int getNoCompartments() { return noCompartments; } } Assume that you have a variable of type Bag initialized to an object instance of type Backpack, as follows: Bag bag = new Backpack(); Show a fragment of code to print the number of compartments in a Bag referenced by the variable bag, as assigned above.