forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrivable.java
More file actions
35 lines (26 loc) · 1.02 KB
/
Drivable.java
File metadata and controls
35 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Java doesn't allow you to inherit from more than one
* class. So, what do you do when you want do you do
* when you want to add additional functionality?
* You create an interface. Interfaces are empty
* classes. They provide all of the methods you must
* use, but none of the code.
*/
// This is how you define an interface. They normally
// have a name that is an adjective. Adjectives modify
// nouns. Most objects have noun names
public interface Drivable {
// You can put fields in an interface, but understand
// that their values are final and can't be changed
double PI = 3.14159265;
// All methods in an interface must be implemented
// They are public and abstract by default
// An abstract method must be defined by any class
// that uses the interface
int getWheels();
// You can't define a method as final and abstract
// final means the method can't be changed and
// abstract means it must be changed
void setWheels(int numWheels);
double getSpeed();
void setSpeed(double speed);
}