Question
JAVA QUESTION: Consider the following code Calling Class: Classes Envelope e = new Envelope(0); e.etype++; System.out.println(e.getWeight()); GiftBox g = new GiftBox(); System.out.println(p.getWeight()); public class Package
JAVA QUESTION:
Consider the following code
Calling Class: | Classes |
Envelope e = new Envelope(0); e.etype++; System.out.println(e.getWeight()); GiftBox g = new GiftBox(); System.out.println(p.getWeight()); | public class Package { public int getWeight(int a , int b) { return a*b; } } public class Envelope extends Package { public int etype; public Envelope(int a) { etype =a; } public int getWeight() { if (etype == 1) {return 6;} return 7; } } public class Box extends Package{ int w,h; public Box (int a , int b) { w=a; h=b; } public Box () { w = 5; h = 2; } public int getWeight() { return w*h; } } public class GiftBox extends Box { public GiftBox() { super(); } public int getWeight() { return super.getWeight() - 2 ; } } public class Customer { protected ArrayList public Customer(Box inbox) { boxes = new ArrayList boxes.add(inbox); } } |
- What would be the output of the Calling class execution?
- Draw the UML diagram for these classes showing relationships and association. Use class names only, do not list properites or methods.
- Name all parent-child combinations.
- Should the annotation @Override be applied to the getWeight method overridden in the Envelope class?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started