แสดงบทความที่มีป้ายกำกับ keyword this และ super แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ keyword this และ super แสดงบทความทั้งหมด

keyword this และ super

22:41 ---

super 

ภายใน method body เพื่ออ้างถึง hidden variable หรือ overridden method ของsuper classเช่น

class MySuperclass
{
boolean myVariable;
void myMethod()
{
myVariable = true;
}
}
class MySubclass extends MySuperclass
{
boolean myVariable;
void myMethod()
{
myVariable = false;
super.myMethod();
System.out println(myVariable);
System.out println(super.myVariable);
}
}

ผลลัพธ์ false
              true


keyword this

class Circle
{
int pointX,pointY,radius;
public Circle(int pointX,int pointY,int radius)
{
this.pointX=pointX;
this.pointY=pointY;
this.radius=radius;
}
}