Interface Variables must be Final

Java-Interface Variables must be Final

Interface Variables must be Final

An interface does not have instance variables. The members of an interface are always declared as static and final, that the variable cannot be modified by the methods in the class. Such variables will be inherited by the class that implements the interface.

Program

Interface Variables must be Final output

Program Source

interface Data {
    
    int data1 = 50;
    int data2 = 100;
}
class ShowData implements Data {
    
    void interfaceValues()
    {
        System.out.println("data1 = "+data1);
        System.out.println("data2 = "+data2);
    }
    
    void modifyInterfaceValues()
    {
        data1 += 20;
        data2 += 40;
    }
}
public class Javaapp {

    public static void main(String[] args) {
        
        System.out.println("data1 = "+Data.data1);
        System.out.println("data2 = "+Data.data1);
        ShowData obj = new ShowData();
        obj.interfaceValues();
        obj.modifyInterfaceValues();
        obj.interfaceValues();
    }
}

Leave a Comment