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 boxes;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!