-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGreetable.java
46 lines (26 loc) · 877 Bytes
/
Greetable.java
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
36
37
38
public interface Greetable {
String greeting = "Hello World";
//variables are public static final whether indicated to be so or not;
void greet();
//methods are public abstract whether indicated to be so or not.
}
class Greeter extends Object implements Greetable {
public void greet() {
System.out.println(greeting);
}
public static void main(String args[]) {
System.out.println(Greetable.greeting);
Greetable MartyMoose = new Greeter();
Greeter gr = (Greeter)MartyMoose;
MartyMoose.greet();
gr.greet();
//Anonymous class -- An implementation of Greetable that we don't give a class
//name to. It's just a Greetable and nothing else.
Greetable whatever = new Greetable(){
public void greet() {
System.out.println("I'm going through the desert with a class with no name.");
}
};
whatever.greet();
}
}