Java????????????
???????????? ???????[ 2013/1/24 11:29:20 ] ????????
???????????interface
?????????????????? ???δ??modifiers????????? interface?? ???????????????????????parent interfaces??????????壨interface body????
???????????£?
public interface GroupedInterface extends Interface1?? Interface2?? Interface3 {
// constant declarations
// base of natural logarithms
double E = 2.718282;
// method signatures
void doSomething (int i?? double x);
int doSomethingElse(String s);
}
????Public?漲?????????????κ???е??κ???????á??????????????????public????????????????????????á?
?????????????????????????????????????????????????????????????????????????????κ?????????
?????????壨interface body??
???????????к????????????????з????????????????????????????????????????????????????????????????????е???????????public?????????δ?public?????????
?????????????????????????????????????δ?public?? static??final?????????
???????????
???????????????????????????????????????????????implements???????????????????????implements?????????????????????????????????????implements?????????extends????????檔
?????????????—Relatable
????Relatable?????????????????????С?????
public interface Relatable {
// this (object calling isLargerThan)
// and other must be instances of
// the same class returns 1?? 0?? -1
// if this is greater // than?? equal
// to?? or less than other
public int isLargerThan(Relatable other);
}
???????????????????????????С?????????????????????????????Relatable????
???????а???????????????С???κ??????????Relatable??????????????????????????????????????????????????????????????????????????漸?ζ????????????????????????????????????????????????????????????????int isLargerThan()??????
??????????????????????Relatable??????????????????????????????
????Relatable???????
????????????????????????????Relatable????
public class RectanglePlus
implements Relatable {
public int width = 0;
public int height = 0;
public Point origin;
// four constructors
public RectanglePlus() {
origin = new Point(0?? 0);
}
public RectanglePlus(Point p) {
origin = p;
}
public RectanglePlus(int w?? int h) {
origin = new Point(0?? 0);
width = w;
height = h;
}
public RectanglePlus(Point p?? int w?? int h) {
origin = p;
width = w;
height = h;
}
// a method for moving the rectangle
public void move(int x?? int y) {
origin.x = x;
origin.y = y;
}
// a method for computing
// the area of the rectangle
public int getArea() {
return width * height;
}
// a method required to implement
// the Relatable interface
public int isLargerThan(Relatable other) {
RectanglePlus otherRect
= (RectanglePlus)other;
if (this.getArea() < otherRect.getArea())
return -1;
else if (this.getArea() > otherRect.getArea())
return 1;
else
return 0;
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11