0

Possible Duplicate:
Why no static methods in Interfaces, but static fields and inner classes OK?

I want to know that why interface do not allow static block, but they allow to declare static variable. What if i want to intialize a static variable on some logic.

edit: Earlier i did not post my query in better form but this is my query with sample code. please look into it.

interface A {
    static class XYZ {
        public static void methodA() {
            // some implementation
            System.out.println("methodA");
        }

        public static void methodB() {
            // some more implementation
            System.out.println("methodB");
        }
    }

    void methodC();
}

public class ABC implements A {
    public static void main(String[] args) {
        A.XYZ.methodA();
    }

    @Override
    public void methodC() {
        // TODO Auto-generated method stub

    }
}

Since purpose of interface is to provide a mechanism where users/implementors of the interface can implement the properties( methods) according to their needs. But if i am allowed to add implementation in interface then some how that purpose of interface is defeated, please make me clear why this implementation in the interface is permitted, there must be something that is why and what is that fact, that is what i want to know

Community
  • 1
  • 1
  • i think the answer to **why interface do not allow static block, but they allow to declare static variable** may be commented in the second duplicated question by @peterk. It is idealogical not technical. – andy Aug 05 '13 at 03:56

1 Answers1

2

They designed interfaces to not allow implementations; a static block would constitute an implementation, so it is not allowed.

vault
  • 3,930
  • 1
  • 35
  • 46