Introduction Flashcards

1
Q

Define an exception that java makes for interfaces !

A

Java makes an exception when it comes to interfaces about multiple inheritance where an interface can implement multiple interfaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define an interface !

A

an interface is an abstract data type that is defined in java with
the keyword interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of members can an interface contain ?

A

An interface can only contain public abstract methods, public static final variables and default methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to declare an interface ?

A

In Java, an interface is defined with the interface keyword, analogous to the class keyword used when defining a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does a class implement an interface ?

A

A class implements an interface using the “implements” keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give the full syntax of declaring an interface and members of
the interface with showing which parts are required and which parts are assumed ?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Give an example of a class implementing more than one interface !

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does that imply ?

A

It does imply that the concrete class is required to implement all of the abstract methods defined in the implemented interfaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly