To understand the working of override keyword in Actionscript 3, follow the article.
Main.as
package
{
import flash.display.MovieClip;
/**
* ...
* @author Abhishek Kumar
*/
public class main extends MovieClip
{
public function main()
{
var oBase:CBase = new CBase();
oBase.method();
var oChild:CChild = new CChild();
oChild.method();
var oClone:CBase = oChild as CBase;
oClone.method();
}
}
}
CBase.as
package
{
public class CBase
{
public function CBase()
{
}
public function method():void
{
trace("CBase -> method");
}
}
}
CChild.as
package
{
public class CChild extends CBase
{
public function CChild()
{
}
public override function method():void
{
trace("CChild -> method");
}
}
}
OUTPUT
CBase -> method
CChild -> method
CChild -> method
Hence, you have seen how the override keyword works in Actionscript 3.
Comments
Post a Comment