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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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"; }

Post 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 35 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply