Core Java 6: Interfaces & Abstract Classes Flashcards

(4 cards)

1
Q

Interface

A
  • abstract type used to declare behavior classes must implement
  • can inherit from as many interfaces as you want (how Java handles multiple inheritance)
  • all fields are public, static, final (constants)
  • all methods are implicitly public
  • interface cannot have constructor
  • any non-abstract methods must use default or static keyword
  • meant for inheritance; meant to define function or group of related functions for child to implement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Abstract classes

A

classes used solely for inheritance, cannot be instantiated directly

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

Abstract method

A

method w/o implementation in class / interface where defined

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

When to use interface vs. abstract class

A

if you need instance variables to inherit, you should use an abstract class; interfaces define something your abstract class can do (behaviors/methods), abstract classes define what classes are; interfaces are intentionally restrictive, so you use them to only inherit method or group of related methods

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