Introduction Flashcards
Define an exception that java makes for interfaces !
Java makes an exception when it comes to interfaces about multiple inheritance where an interface can implement multiple interfaces
Define an interface !
an interface is an abstract data type that is defined in java with
the keyword interface
What type of members can an interface contain ?
An interface can only contain public abstract methods, public static final variables and default methods
How to declare an interface ?
In Java, an interface is defined with the interface keyword, analogous to the class keyword used when defining a class.
How does a class implement an interface ?
A class implements an interface using the “implements” keyword
Give the full syntax of declaring an interface and members of
the interface with showing which parts are required and which parts are assumed ?
when declaring an interface , the ‘abstract’ specifier is assumed and the ‘interface’ keyword is required.
When declaring a variable inside an interface, it is assumed to be public and static and final.
When declaring a method inside an interface, it is assumed to be abstract and public
Give an example of a class implementing more than one interface !
public class Elephant implements WalksOnFourLegs, HasTrunk, Herbivore {
}
In the example, if any of the interfaces defined abstract methods, the concrete class Elephant would be required to implement those methods
What does that imply ?
It does imply that the concrete class is required to implement all of the abstract methods defined in the implemented interfaces