Java-Interface Variables must be Final

Interface Variables must be Final

The members of an interface are always declared as final, that the variable cannot be modified by the methods in the class.

Program

0

Program Source

interface Data {
    
    int data1 = 50;
    int data2 = 100;
}

class Data1 implements Data {
    
    void getInterfaceValues()
    {
        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) {
        
        Data1 obj = new Data1();
        obj.getInterfaceValues();
        obj.modifyInterfaceValues();
        obj.getInterfaceValues();
    }
}

Leave a Comment