为什么一个对一个错呢?
飞行的兔子 2004-06-27 08:08:37 两个程序相似的用法!但出现不同的结果!
程序一:
class Bow1{
Bow1(int marker){
System.out.println("Bow1("+marker+")");
}
void f(int marker){
System.out.println("f("+marker+")");
}
}
class Table{
static Bow1 b1=new Bow1(1);
Table(){
System.out.println("Table()");
b2.f(1);
}
void f2(int marker){
System.out.println("f2("+marker+")");
}
static Bow1 b2=new Bow1(2);
}
class Cupboard{
Bow1 b3=new Bow1(3);
static Bow1 b4=new Bow1(4);
Cupboard(){
System.out.println("Cupboard()");
}
void f3(int marker){
System.out.println("f3("+marker+")");
}
static Bow1 b5=new Bow1(5);
}
public class StaticInitialization{
public static void main(String args[]){
System.out.println("Creating new Cupbaord() in main");
new Cupboard();
System.out.println(
"Creating new Cupboard() in main");
new Cupboard();
t2.f2(1);
t3.f3(1);
}
static Table t2=new Table();
static Cupboard t3=new Cupboard();
}
程序二:
class point{
float x;
float y;
point(float x,float y){
this.x=x;
this.y=y;
System.out.println("after ininizing x:"+this.x+"\ty:"+this.y);
}
}
public class TestThis extends point{
TestThis(float x,float y){
super(x,y);
System.out.println("class TestThis extends from point!");
}
public static void main(String args[]){
TestThis tt=new TestThis(2.0,3.0);
static point pt=new point(12.0,3.0);
tt.finalize();
pt.finalize();
}
}
程序一能顺利通过,而程序二却报错;
错误提示为:
TestThis.java;illegal start of expression
static point pt=new point(3.0,2.0)