-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
40 lines (32 loc) · 890 Bytes
/
Copy pathApp.java
File metadata and controls
40 lines (32 loc) · 890 Bytes
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
39
40
package tutorial25;
// anonymous class lesson
class Machine {
// make a class with a start method that is overriden
public void start(){
System.out.println("Starting machine...");
}
}
// this interface is implemented in the anonymous classes object
interface Plant {
public void grow();
}
public class App {
public static void main(String[] args) {
// we instantiate an instance that is named Machine
// but doesn't have method of Machine so its anonymous
Machine machine1 = new Machine() {
@Override public void start(){
System.out.println("camera snapping..");
}
}; // this is odd place for semicolon..
machine1.start();
// instantiates an object with only an interface defined?
Plant plant1 = new Plant(){
@Override
public void grow() {
System.out.println("Plant growing");
}
}; // another odd place to note the semicolon
plant1.grow();
}
}