-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterface.java
48 lines (43 loc) · 1.09 KB
/
Interface.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
39
40
41
42
43
44
45
46
47
48
/* Interface: It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
* Rules||||||||||||||||||
* You cannot instantiate an interface.
* An interface does not contain any constructors.
* All of the methods in an interface are abstract.
* An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.
* An interface is not extended by a class; it is implemented by a class.
* An interface can extend multiple interfaces.
*/
public class Interface
{
public static void main(String[] args)
{
Husky h = new Husky();
h.eat();
h.travel();
h.Bark();
}
}
interface Animal
{
public void eat();
public void travel();
}
interface Dog extends Animal
{
public void Bark();
}
class Husky implements Dog
{
public void eat()
{
System.out.println("Husky loves to eat cookies.");
}
public void travel()
{
System.out.println("Husky does travel in the owner's Jeep.");
}
public void Bark()
{
System.out.println("Bao! Baoo!");
}
}