From my reading of the spec, interface methods are package-private by default
unless declared public. From the following compiler error it seems they are
public by default.
DREL 5/9/96
springbok /tmp [26] % /usr/local/java/nightly/jdk1.1/bin/javac a.java
a.java:8: Methods can't be overridden to be more private. Method void method0() is public in interface foo.A.
void method0() {}
^
1 error
springbok /tmp [27] % cat a.java
package foo;
interface A {
void method0();
}
class a implements A {
void method0() {}
}
[meiphen 5/14/96]
A customer from Unify has encountered this same problem and is reporting
the bug with JDK1.0 beta release, although the bug still exists in JDK1.0.2:
% javap -version
javap version "JDK1.0beta"
The public keyword is being applied to interface definitions even when
it is not included in soruce.
-------------------- ifacetest.java source
/* not public */
interface ifacetest
{
void testit(); // not public
}
-------------------- dissassemble the compiled class
% javap ifacetest
Compiled from ifacetest.java
interface ifacetest extends java.lang.Object {
public abstract void testit();
}
-------------------- imptest.java source to implement ifactest
class imptest implements ifacetest
{
void testit()// not public
{
}
}
-------------------- compile this and see what happens.
javac imptest.java
imptest.java:4: Methods can't be overridden to be more private. \\
Method void testit() is public in interface ifacetest.
void testit()// not public
^
1 error
Added public modifier to imptest.testit() and it will compile.
unless declared public. From the following compiler error it seems they are
public by default.
DREL 5/9/96
springbok /tmp [26] % /usr/local/java/nightly/jdk1.1/bin/javac a.java
a.java:8: Methods can't be overridden to be more private. Method void method0() is public in interface foo.A.
void method0() {}
^
1 error
springbok /tmp [27] % cat a.java
package foo;
interface A {
void method0();
}
class a implements A {
void method0() {}
}
[meiphen 5/14/96]
A customer from Unify has encountered this same problem and is reporting
the bug with JDK1.0 beta release, although the bug still exists in JDK1.0.2:
% javap -version
javap version "JDK1.0beta"
The public keyword is being applied to interface definitions even when
it is not included in soruce.
-------------------- ifacetest.java source
/* not public */
interface ifacetest
{
void testit(); // not public
}
-------------------- dissassemble the compiled class
% javap ifacetest
Compiled from ifacetest.java
interface ifacetest extends java.lang.Object {
public abstract void testit();
}
-------------------- imptest.java source to implement ifactest
class imptest implements ifacetest
{
void testit()// not public
{
}
}
-------------------- compile this and see what happens.
javac imptest.java
imptest.java:4: Methods can't be overridden to be more private. \\
Method void testit() is public in interface ifacetest.
void testit()// not public
^
1 error
Added public modifier to imptest.testit() and it will compile.