1. Draw a UML diagram for a class hierarchy that contains data definition classe
ID: 3721751 • Letter: 1
Question
1. Draw a UML diagram for a class hierarchy that contains data definition classes and the relationships between the following data definition classes: Fruit, Banana, Apple. Assume it is impossible to create a Fruit object. Then, briefly justify your design.
2. Consider the following Java interface. Based on this interface, identify one problem with the interface and then identify how it should be fixed.
public interface Sizable {
double size;
double getSize();
}
3. Using course terminology, explain the difference between inheritance and composition. When would a programmer use inheritance vs. composition. In your answer provide an example of each.
Explanation / Answer
Hi Friend,
Please post one question in a post as per the chegg guideline.
I have answered Q2.
public interface Sizable {
double size;
double getSize();
}
All the methods in interface are declared with empty body and are public and all fields are public, static and final by default.
By default all methods are public and abstract in Interface.
So, double getSize() : this is fine
double size : this is not fine, size is not defined as public, static and final
public interface Sizable {
final double size = 10;
double getSize();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.