文档介绍:XX
毕业设计(论文)说明书
英文翻译
学 院计算机科学与技术学院
班 级 网络工程专X班
姓 名 X
学 号 X
指导教师 %
二OX年六月十七日
Literature
Interfaces
The intm the Woodwind and Brass classes that once you've implemented an interface, that implementation becomes an ordinary class that can be extended in the regular way.
You can choose to explicitly declare the methods 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.
You can see this in the modified version of the Instrument example. Note that every method in the interface is strictly a declaration, which is the only thing the compiler allows. In addition, none of the methods in Instrument are declared as public, but they're automatically public anyway:
//: interfaces/music5/
// Interfaces.
package ;
import ;
import static .*;
interface Instrument (
// Compile-time constant:
int VALUE = 5; // static & final
// Cannot have method definitions:
void play(Note n); // Automatically public
void adjustQ;
}
class Wind implements Instrument (
public void play(Note n) ( print(this + ”.play() ” + n);
)
public String toStringO ( return "Wind"; } public void adjust() ( print(this + ".adjust。"); ) )
class Percussion implements Instrument ( public void play(Note n) ( print(this + ”.play() ” + n);
)
public String toStringO ( return "Percussion"; } public void adjust() ( print(this + ".adjust。"); ) )
class Stringed implements Instrument (
public void play(Note n) ( print(this + ”.play() ” + n);
)
public String toStringO ( return "Stringed"; } public void adjust() ( print(this + ".adjust。"); ) )
class Brass extends Wind (
public String toStringO ( return "Brass"; }
)
class Woodwind extends Wind