Chap 9 Interface And Package Flashcards

1
Q

What’s difference between abstract class and an interface?

A

A class can implement more than one interface, but can only inherit one superclass.

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

What is value of an interface

A

Can specify what a class must do, but not how.

A consistent way to invoke similar behavior in different objects

Specifies the method, but body is blank

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

How are interface created

A

Access interface name {

Method one();
Method two();

}

Body is blank

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

Write a class that implements an interface class IntyFc

A

class TestClass implements IntyFc
{}

The methods inside must be public

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

If implementing an interface, do the methods inside must be public?

A

Yes

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

Can you create a reference variable of the interface type and call the method defined in the subclass?

A

Yes. But only the ,ethics that were defined in the interface

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

Can you implement an interface but not implement the methods required?

A

Yes but you have to label it abstract

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

What access level must interfaces be?

A

Either public, or defaulted to its package level

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

Can you declare an interface within a class?

A

Yes, called a nested interface

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

Can interfaces extend other interfaces?

A

Yes

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

Explain default interface methods

A

An interface can define the body of a method as its default, if it’s not overloaded in the class. It’s useful if a popular interface adds a new method requirement, having the default won’t break the subclasses if they don’t update.

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

What is the defining difference between an interface and a class

A

Interface cannot maintain state information, a class can.

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

Example code: define a default method in an interface

A

default String methodOne ()
{ return String;
}

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

Can an implementing class override a default method?

A

Yes, it’s common

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

Hierarchy of inheriting interface methods

A

Class implementation takes priority
Then an inheriting class
If implement two interfaces with same method name, it’ll throw error

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

Why include a static method in interface?

A

Can call it without needing an impmentation of it

17
Q

T/F: the visibility of a subclass method cannot be more restrictive than the base class method?

A

True

18
Q

T/F: The methods of an interface or implicitly public and abstract?

A

TRUE

19
Q

Whats popular method for defining constants and bringing to a class?

A

Write a class with the constants defined as public static final.

Then import that class package into the next class using it

20
Q
A