Closed dhafinrazaq closed 3 years ago
An interface has its methods declared abstract and public by default. By virtue of that, the subsequent class (Moo) HAS to implement an interface to instantiate the abstract method or else be an abstract class itself. Hence why option A is correct, which also does not conflict with the quiz question either.
Thanks and I'm not sure if I understand it correctly, but if it is the case where the Goo#store()
has a default implementation (for example, inside the interface Goo, default void store() { System.out.println(""); }
is declared), Moo does not have to override/declare its own store()
method, and thus Moo can be compiled (I've already tried to compile a class that implements an interface with default method implementation, example here).
All classes that implement an interface must implement ALL the methods or else it will not compile, in this case Moo
class needs Moo#store()
for it to compile. But when it becomes an abstract class, it can compile without Moo#store()
Is it possible to represent default methods in interface in a uml diagram?
By default
you are referring to the visibility modifier right? If that is the case, the default is package private
. So you can technically show the visibility using the tilda symbol "~"
@joshtyf i think he's referring to methods in an interface, so the default should be public, or "+"
@joshtyf I think the default
refers to method declared with a default implementation
Ah okay my bad. Hmm, then I think default methods should just be represented in the same way as you would for a normal method.
In the question below, it seems that interface is assumed to be pure (without default implementation). This is because if the interface
Goo
has adefault
implementation forstore()
, I think option A should also be incorrect (Moo
can be compiled). Example here
That option is considered the correct answer because if the statement doesn't indeed compile, it has nothing to do with Foo
being an abstract class.
Assume there are no default methods if not specifically mentioned.
I see, thanks prof and everyone else
Hi Prof @damithc ,
In the question below, it seems that interface is assumed to be pure (without default implementation). This is because if the interface
Goo
has adefault
implementation forstore()
, I think option A should also be incorrect (Moo
can be compiled). Example hereHowever, in this quiz, we do not have such assumption.
In the exam, can we assume that interface/abstract class has no default implementation (especially if the method name is listed in the UML diagram)?
Thank you