Friday, May 22, 2009

All methods of a interface are public

import java.io.IOException;

 

interface TestInterface

{

        void test() throws IOException;

}

 

public class Second implements TestInterface

{

        void test() throws IOException

        {

                System.out.println("Second.test() invoked");

        }

 

        public static void main(String[] args) throws IOException

        {

                Second j = new Second();

                j.test();

        }

}

 

C:\users\Babu\temp\java>javac Second.java

Second.java:10: test() in Second cannot implement test() in TestInterface; attempting to assign weaker access privileges; was public

        void test() throws IOException

             ^

1 error

No comments: