首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

这个方法的如何没有方法题(绝非抽象方法)

2012-02-05 
这个方法的怎么没有方法题(绝非抽象方法)classGarbage{intindexstaticintcountGarbage(){count++System

这个方法的怎么没有方法题(绝非抽象方法)
class   Garbage  
{  
int   index;  
static   int   count;  
Garbage()  
{  
count++;  
System.out.println( "object   "   +   count   +   "   construct! ");  
setId(count);   //这个是方法么怎么没有方法体呢?  
}  
void   setId(int   id)  
{  
index=id;  
}  
protected   void   finalize()  
{  
System.out.println( "object   "   +   index   +   "   is   reclaimed! ");  
}  
public   static   void   main(String[]   args)  
{  
new   Garbage();  
new   Garbage();  
new   Garbage();  
new   Garbage();  
System.gc();  
}  
}  

setId(count);   //这个是方法么怎么没有方法体呢?

[解决办法]
那个不是方法调用么?
调用你下面那个
void setId(int id)
{
index=id;
}
count用来表示对象的数量,并为其编号
[解决办法]
如果写到一个里,就写死了。如果再有其它的方法想调用这个set(count)方法,就要重新再声明一个。

热点排行