1
2
|
public
static
int
age;
private
static
int
method() { … }
|
1
|
public
static
final
int
age =
10
;
|
1
2
3
4
5
|
final
class
C {
private
final
int
a;
private
final
int
b;
public
C(
int
a,
int
b) {
this
.a=a;
this
.b=b; }
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public
abstract
class
Shapes {
//抽象类
public
int
x, y;
public
int
width, height;
public
Shapes(
int
x,
int
y,
int
width,
int
height) {
this
.x = x;
this
.y = y;
this
.width = width;
this
.height = height;
}
abstract
double
getArea();
//抽象方法
abstract
double
getPerimeter();
//抽象方法
}
public
class
Circle
extends
Shapes {
//子类
public
double
r;
public
Circle(
int
x,
int
y,
int
width,
int
heigh) {
super
(x, y, width, heigh);
r = (
double
) width /
2.0
;
}
public
double
getArea() {
//实现父类的抽象方法
return
(r * r * Math.PI);
}
public
double
getPerimeter() {
//实现父类的抽象方法
return
(
2
* Math.PI * r);
}
}
|
1
|
abstract
void
method();
|