- Assume You Have The Following Two Classes Public Class Bag Private String Name Public Bag Name Fancy Bag 1 (87.58 KiB) Viewed 40 times
Assume you have the following two classes: public class Bag { } private String name; public Bag() { name= "Fancy bag"; }
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Assume you have the following two classes: public class Bag { } private String name; public Bag() { name= "Fancy bag"; }
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.