重载:
public class Circle {
private int x,y,r;
private double pi=3.1415;
public Circle(int x,int y) {
this.x=x;
this.y=y;
r=1;
this.prt();
}
public Circle(int x,int y,int r) {
this.x=x;
this.y=y;
this.r=r;
this.prt();
}
public void prt() {
System.out.println("x="+x+",y="+y+",r="+r);
}
public static void main(String[] args) {
Circle c1=new Circle(10,10);
Circle c2=new Circle(20,20,10);
}
}
覆盖:
class PrintFather {
int i=1;
public void prt() {
System.out.println("i="+i);
}
}
public class PrintOverriden extends PrintFather {
String name="PrintOverriden";
public void prt() {
System.out.println("Name="+name);
System.out.println("i="+i);
}
public static void main(String[] args) {
PrintOverriden p=new PrintOverriden();
p.prt();
}
}
重构:
是针对代码,写得不好自然要重新来写,这就是重新构造代码. |