-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut33.java
More file actions
63 lines (50 loc) · 1.13 KB
/
Tut33.java
File metadata and controls
63 lines (50 loc) · 1.13 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package tutorial;
//lambda Expresssion
interface Animal_Sounds {
public void Dog();
public void Cat(String sound);
}
@FunctionalInterface
interface Buffalo {
public void Sound();
}
@FunctionalInterface
interface Cow {
public void Cowsound(String sound);
}
public class Tut33 {
public static void main(String[] args) {
// you can implements this interface either implementing with or class or
// creating the annoymous class
Animal_Sounds an = new Animal_Sounds() {
@Override
public void Dog() {
System.out.println("Bow Bow");
}
@Override
public void Cat(String sound) {
System.out.println(sound);
}
};
// calling the interface function
an.Cat("Meow Meow");
an.Dog();
anothermethod();
anotherlamba();
}
// lambda expression works with only functional interface
// lambda expression without parameter
public static void anothermethod() {
Buffalo an = () -> {
System.out.println("Moww Moww");
};
an.Sound();
}
// lambda expression with one parameter
public static void anotherlamba() {
Cow c = (sound) -> {
System.out.println(sound);
};
c.Cowsound("Mowwwwwww chotta");
}
}