标签:
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),必须是第一条语句。
}
|
标签:
原文地址:http://www.cnblogs.com/milliard/p/5533168.html