参考一下:
http://zhangjunhd.blog.51cto.com/113473/20531/
class
Person {
protected
void
print() {
System.
out
.println(
"The print() in class Person."
);
}
}
public
class
DemoSuper
extends
Person {
public
void
print() {
System.
out
.println(
"The print() in class DemoSuper."
);
super
.print();
//
调用父类的方法
}
public
static
void
main(String[] args) {
DemoSuper ds =
new
DemoSuper();
ds.print();
}
}
|
public
class
DemoThis {
private
String
name
;
public
void
setName(String name) {
this
.
name
= name;
//
前一个
name
是
private name
;后一个
name
是
setName
中的参数。
}
}
|
Button
bn
;
…
bn.addActionListener(
this
);
|
class
Person {
public
static
void
prt(String s) {
System.
out
.println(s);
}
Person() {
prt(
"A Person."
);
}
Person(String name) {
prt(
"A person name is:"
+ name);
}
}
public
class
Chinese
extends
Person {
Chinese() {
super
();
//
调用父类构造函数。
prt(
"A chinese."
);
}
Chinese(String name) {
super
(name);
//
调用父类具有相同形参的构造函数。
prt(
"his name is:"
+ name);
}
public
static
void
main(String[] args) {
Chinese cn =
new
Chinese();
cn =
new
Chinese(
"kevin"
);
}
}
|
Point(
int
a,
int
b){
x=a;
y=b;
}
Point(){
this
(1,1);
//
调用
point(1,1),
必须是第一条语句。
}
|