What is interface for java in Hindi ? ( जावा मे interface क्या होते हैं।)

Interface:- Multiple inheritance में इस प्रकार का declaration java support नही करती है।

Class C extend A extend

क्योंकि java में एक से ज्यादा super class नही हो सकती है।
इस प्रकार के inheritance को support कराने के लिए java interface का use करती है। क्योंकि हम एक से ज्यादा class को extend नही कर सकते हैं। परन्तु एक से ज्यादा interface को implement किया जा सकता है
Interface :-  interface एक special प्रकार की class है। interface में class की ही तरह variable के method abstract तथा field final होते हैं।

Ex:-   interface को बनाने के लिए
Interface interface name
{
Method
——-
——-
}

Working with Interfaces:- 

Interfaces को declare करना बिलकुल आसान होता है। इसके लिए आप interface keyword यूज़ करते है। पहले तो आप public access modifier define करते है, इसके बाद आप interface keyword लिख कर interface का नाम लिखते है। इसके बाद curly brackets में आप उन सभी methods को declare करते है जो आप किसी class से implement करवाना चाहते है। वैसे तो interfaces के अंदर सभी methods by default public होते है। लेकिन आप चाहे तो public access modifier सभी methods के आगे add कर सकते है। इसका उदाहरण नीचे दिया जा रहा है।

Structure Example

public interface interface_Name
{
// methods without body;
}
public interface yrFriend
{
public void sales();
public void production();
public void accounts();
public void management();
}

जैसे की मैने आपको पहले बताया implements keyword को यूज़ करते हुए कोई भी class आसानी से interface को implement कर सकती है। Interfaces का complete उदाहरण निचे दिया जा रहा है।

Example
public interface yourFriend
{
     public void sales();
public void production();
public void accounts();
public void management();
}
public class You implements yourFriend
{
     public void sales()
{
// implement sales department
     }
     public void production()
{
// implement production department
}
public void accounts()
{
// implement production department
}
public void management()
{
    // implement production department
}
}

 

 

Leave a Comment