PDA

View Full Version : override question


dsdsdsdsd
10-26-2008, 08:21 PM
hello;

I am learning how to extend my own custom classes;

for instance I have:

// class A
public function a_method() : void
{ trace( "hello class A , a_method");
}



// class B extends A
override public function a_method()
{ trace( "hello class B , a_method");
}


it works fine;

QUESTION: how can I make the class B method override BUT YET ALSO call the class A method?

thus the output should be:
hello class B , a_method
hello class A , a_method



thanks,
Shannon

CyanBlue
10-26-2008, 08:28 PM
Maybe you just need to call super(); inside your function to execute what's in Class A???

Mazoonist
10-26-2008, 08:31 PM
override public function a_method() {
trace("hello class B , a_method");
super.a_method();
}
BTW, "super()" would call the constructor of A

dsdsdsdsd
10-26-2008, 08:59 PM
interesting, it works ... I have to ask then: how can super be a method and a class??

super() AND super....()




thanks,
Shannon

wvxvw
10-26-2008, 09:06 PM
super isn't actually a method, it's a directive / keyword, whatever definition you like the best. When it's super() it executes the constructor of the superclass, if it's super.someMethod it executes the someMethod of the superclass.
Imagine you'd need (theoretically) to instantiate the class from within constructor, not calling new MyClass(), than, it would look like "this()", so, super replaces "this" of the superclass.