# 24) Interfaces

### Need of Interfaces:

![](/files/-LU8xCELPRnZfkDJuFrs)

![](/files/-LU8xGmPWMtS9pxAqrTM)

![](/files/-LU9vY4YsUA3BsiMhlqQ)

### Example:

Suppose we have two classes Programmer and Manager both of them extend some common feature from Employee class.Now let say we have the below requirement/behavior to implement

![](/files/-LU9wS4a1-EGDPvc3CqO)

![](/files/-LU9xRI7DSHoCwrTptJv)

### That's the reason why interface are needed

![](/files/-LU9xkwj8Oa1kzr6i4TG)

![](/files/-LU9xw9sBOPDZFEUUSb1)

![](/files/-LU9y3QHoT7qUK6QSA75)

![](/files/-LU9yDJMko3hSyX9jKzd)

#### Code:

```java
package com.gs.ilp.corejava.interfaces;

public interface Interviewer {
	public void conductInterview();
}
```

```java
package com.gs.ilp.corejava.interfaces;

public interface Trainable {
	public void attendTraining();
}
```

```java
package com.gs.ilp.corejava.interfaces;

public class Employeeee {
	String name;
	String address;
	String phoneNumber;
	String experience;
}
```

```java
package com.gs.ilp.corejava.interfaces;

public class Manager extends Employeeee implements Interviewer, Trainable {
	int teamSize;
	void reportProjectStatus() {
	}
	public void attendTraining() {
		System.out.println("Mgr - attendTraining");
	}
	public void conductInterview() {
		System.out.println("Mgr - conductInterview");
	}
}
```

```java
package com.gs.ilp.corejava.interfaces;

public class Programmer extends Employeeee implements Trainable {
	String[] programmingLanguages;
	void writeCode() {
	}
	public void attendTraining() {
		System.out.println("Prog - attendTraining");
	}
}
```

```java
package com.gs.ilp.corejava.interfaces;

public class TestInterfaces {
	public static void main(String[] args) {
		Manager manager = new Manager();
		manager.attendTraining();
		manager.conductInterview();

		Programmer programmer = new Programmer();
		programmer.attendTraining();
	}
}
```

#### Output:

![](/files/-LawneOZTPLhBTd9Sw6T)

#### UML :

![](/files/-LU9ySZ8Q-kp4ufMmdSt)

### Defining Interfaces:

![](/files/-LU9zEBMn061VJ9qBkYj)

![](/files/-LU9zNZiGWOhtZ9ZS8Pq)

![](/files/-LU9zXWHmgcKIMwnvxce)

![](/files/-LU9zdnd_CzOoEvos8EW)

![](/files/-LU9zjwyD4NtKeNqX1Gc)

![](/files/-LU9zuRdGYB3HW2BqhWJ)

![](/files/-LUA-2Qt8cI1P8NxDR_I)

![](/files/-LUA-9GkYGqS6KX_Cx9x)

### Types of methods in an interface :

![](/files/-LUA-bv3aDsqgWF1D_-f)

![](/files/-LUA-hiT0krVh0b4Omf0)

![](/files/-LUA-nUnW9lT1v8EKvIo)

### Rules to implement Interface:

![](/files/-LUA8G2Y-TxDIZlYg_4D)

![](/files/-LUA8NqXvlGDLwgWzf9l)

### A class can implement multiple interfaces:

#### Rule 1:

![](/files/-LUAAfG0JjGr_tVch42l)

![](/files/-LUAAjErurwm14ao1tgq)

![](/files/-LUAB02iPzXEydhWJsFO)

![](/files/-LUAB4xX33280Qow7wEr)

#### Rule 2:

![](/files/-LUADFenNMC-87LYlFwu)

![](/files/-LUADLn2aVsc-rgTwHB6)

### Multiple inheritance is possible using Interfaces:

![](/files/-LUADvwUypd8KnrMc-8C)

![](/files/-LUAE44fJ7l9P5TZjxxX)

![](/files/-LUAEKbXIzSylYYjmI2a)

### Properties of a member of an interface:

![](/files/-LUAEu1F7TTUnnC9Nsmi)

![](/files/-LUAEytCC38XoXDSCKDC)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-java.gitbook.io/core-java/interfaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
