public interface TestInterface
{
void method1();
void method2();
String method3();
}public class TestImplement implements TestInterface
{
void method1()
{
System.out.println("method1");
} @Override
void method2()
{
System.out.println("method2");
} @Override
String method3() { return "method3";
}}
Without any IDE, please tell me the wrong of this segment of code and the reason in java
西西,几乎是散分了,来接分,结帐的时候加100
{
void method1();
void method2();
String method3();
}public class TestImplement implements TestInterface
{
void method1()
{
System.out.println("method1");
} @Override
void method2()
{
System.out.println("method2");
} @Override
String method3() { return "method3";
}}
Without any IDE, please tell me the wrong of this segment of code and the reason in java
西西,几乎是散分了,来接分,结帐的时候加100
{
void method1();
void method2();
String method3();
}public class TestImplement implements TestInterface
{
public void method1()
{
System.out.println("method1");
} public void method2()
{
System.out.println("method2");
} public String method3() { return "method3";
}}
不过我这里帖下thinking in java 的原文吧
英文的...我只有英文版的说
you can choose to explicitly declare the method declarations in an interface as public,but they are public even if you don't say it. So when you implement an interface, the methods from the interface must be defined as public.Otherwise they would default to package access, and you'd be reducing the accessibility of a method during inheritance, which is not allowed by the java compiler
they are public even if you don't say it. So when you implement an interface, the methods
from the interface must be defined as public.Otherwise they would default to package access,
and you'd be reducing the accessibility of a method during inheritance, which is not allowed
by the java compiler