Java OOP SHORT
ANSWER QUESTIONS INTERFACES
& POLYMORPHISM SOLUTIONS
2-class, interface 3-method 4-true 5-all 6-a 7-b 8-b 9-d 10-no 11-@Override 12-true 13-Both method headers are missing their return-type.
15-Because
the method() in Coconut does not have an int
parameter, it is not a match to the methodA in the
interface. So
we are not implementing the methods from the interface. 16-The
@Override used over methodC() means that methodC() would
have to be in the interface. As it is
not there, Java gives an error. We
could simply remove @Override over the methodC
header. 17-compareTo(Object o) 18-We could call compareTo
using two strings like this: String
s2 = "apple"; System.out.println(s1.compareTo(s2));
String[] arr = {"zebra", "cat", "lion", "tiger", "dog", "fish"}; Arrays.sort(arr); System.out.println(Arrays.toString(arr)); 19-Here are the outputted values: b) 32 (positive,
because l comes after L in the ascii chart – 32 characters later) c)-10 (negative, because
l comes before v alphabetically – 10 letters before) d) 10 (positive,
because v comes after l alphabetically – 10 letters later) e) 2 (positive,
because c comes alphabetically after a – 2 letters after) f)-6 (negative, after
the tied l letters, the o comes before u – 6 letters before 20-The order:
21-Strings
are sorted alphabetically, or alphanumerically. However, all capital letters appear before
all lower case letters in the sorting alphabet. And numbers appear before all letters. (Symbols also have an order but we won’t
worry about this now.) |
|