this是怎么用的,在这里是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/29 12:49:45
public class Ex5_1 {

private int length;
private int width;
public int getArea()
{
return width*length;
}
public int getPerimeter()
{
return (2*(width+length));
}

/** Creates a new instance of Ex5_1 */
public Ex5_1(int length,int width) {
this.length=length;
this.width=width;
}
public static void main(String args[])
{
Ex5_1 rect=new Ex5_1(10,20);
System.out.println("矩形面积="+rect.getArea());
System.out.println("矩形周长="+rect.getPerimeter());
}

public interface rec_Area
{
int getArea();
}
public interface rec_Perimeter()
{
int getPerimeter();
}
class rectangle implements rec_Area,rec_Perimeter
{ int width,length;
rectangle(int w,int l)
{width=w;
length=l;
System.out.println("width="+width+"----------"+"length="+length

this 属性
this

引用对象或影片剪辑实例。执行脚本时,this 引用包含该脚本的影片剪辑实例。在调用方法时,this 包含对包含所调用方法的对象的引用。

在附加到按钮的 on() 事件处理函数中,this 引用包含该按钮的时间轴。在附加到影片剪辑的 onClipEvent() 事件处理函数中,this 引用该影片剪辑自身的时间轴。

因为 this 是在包含它的脚本的上下文中计算的,所以您不能在脚本中使用 this 来引用在类文件中定义的变量。