-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple.java
More file actions
40 lines (34 loc) · 919 Bytes
/
multiple.java
File metadata and controls
40 lines (34 loc) · 919 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
// MultipleinheritanceExample.java
// Main class
public class MultipleInheritanceExample {
public static void main(String[] args) {
// Creating object of Dog class
Dog d = new Dog();
// Calling methods from both interfaces and Dog class
d.eat(); // from Animal interface
d.play(); // from Pet interface
d.bark(); // from Dog class
}
}
// First parent Interface
interface Animal {
void eat(); // method declaration only
}
// Second parent interface
interface Pet {
void play(); // method declaration only
}
// Child class implementing multiple interfaces
class Dog implements Animal, Pet {
@Override
public void eat() {
System.out.println("Dog can eat");
}
@Override
public void play() {
System.out.println("Dog can play");
}
public void bark() {
System.out.println("Dog can bark");
}
}