Overriding Methods and super.method()

I've got some custom classes that extend and extension of the
MovieClip. At the end of the movieclip timeline I want the end
users to be able to simply call myMethod to signal they are at the
end of the timeline. Certain classes will need to do something
things and others yet others, but they will all also need to do a
few things in common.
I was hoping to define the "in common" things in the super
class and then overide the method for the extensions. So in my
example I was hoping that an instance of Class B would do what it
needed to do and then call the super function. However Class C has
nothing specific itself to do and since the method wasn't overriden
the same myMethod() on the timeline would invoke the super classes
method.
So the case of Class C works. But in the case of Class B. I
get the trace that the Class B method has been called, but I don't
get a message that Class A was called. Is there a way to make this
idea work? Is it a good idea? What am I missing?

Okay I've worked it out. The trick comes in with how you call
myMethod(). On the timeline I have to be sure and use a qualified
reference. So, this is on the of an instance of B, if I use
myMethod();
I only get the myMethod() from class B, but if I do:
this.myMethod()
I get B and A. But oddly enough if I say invoke myMethod from
the constructor of B, I get both trace statements -- regardless of
whether or not I use a qualified reference! Now that is strange.

Similar Messages

  • Extending classes and overriding methods

    If I have a class which extends another, and overrides some methods, if I from a third class casts the extending class as the super class and calls one of the methods which gets overrided, is it the overrided method or the method of the superclass which get executed?
    Stig.

    Explicit cast can't enable the object to invoke super-class's method. Because dynamic binding is decided by the instance. The cast can just prevent you from using methods only defined in sub-class, but it does not let the object to use super-class's method, if the method's been overrided. Otherwise, the polymophism, which is one of the most beautiful feature of Object-Oriented thing, can't be achieved. As far as I know, the only way to use super-class's method is the super keyword in the sub-class, and seems no way for an object to do the same thing (I may wrong, since I haven't read the language spec).
    here's a small test:
    public class Test {
    public static void main(String[] args){
    A a = new B();
    a.method();
    ((A)a).method();
    class A{
    public void method(){
    System.out.println("A's method");
    class B extends A{
    public void method(){
    System.out.println("B's method");
    The output is:
    B's method
    B's method

  • When overriding methods, should i call super at the begining or end

    Hi,
    when overriding methods such as swing's dispose(), and removeNotify(), should i call the super methods at the begining of the method or at the end?
    or does it make a difference....i was under the assumption i should call it at the end, that way i can do whatever necessary things i needed, then call the default....

    In cases where it truly doesn't matter, I think people tend to call super first. If I see it done some other way, it's an indicator that something unusual is going on. I'd liken calling super at the end of a method to iterating through an array in reverse inside of a 'for' loop. One can adopt either convention but people may get confused if you pick the less common one for no particular reason.

  • Why do we need to override Hascode and Equals method?

    Hi,
    == checks if the two references are equal and .equlas will check if the value is same, if we want .equals to take care of both reference and value are correct. why cant I just override equals with an extra check that references are equal(==).
    Please someone elaborate on this and also tell me what role hashcode plays in this.
    thanks
    Anirudh

    anirudh1983 wrote:
    if we want .equals to take care of both reference and value are correct. why cant I just override equals with an extra check that references are equal(==).Many equals() methods do run an '==' check first for efficiency (and I would recommend it if you're writing one yourself).
    Please someone elaborate on this and also tell me what role hashcode plays in this.The reason that it is good practise to override equals() and hashCode() together is to maintain consistency.
    Hashcodes are used by all Java collections that contain the word 'Hash' in their name, and may also be used by other programs that need a hash code for identification; so if you supply one, you must follow the rules (which you can find in the API for Object.equals() and Object.hashCode()).
    The main rule is this: *objects that are equal() must have equal hashcodes*.
    Note that the reverse is NOT true: objects that are not equal() do not have to have different hashcodes, but it is usually better if they do.
    There is quite a lot to know about hashcodes, and what makes a good one, so I suggest you follow dcminter's advice if you want to be a happy and prosperous Java programmer.
    Winston

  • Override method on an object construted by somebody

         customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
                   protected BookmarkablePageLink getBookmarkablePageLink() {
                        BookmarkablePageLink bookmarkablePageLink=   new BookmarkablePageLink("link",clazz){
                             protected void onBeforeRender() {
                                  super.onBeforeRender();
                        return bookmarkablePageLink;
              customMenuComponent.addCustomLink(new CustomLinkComponenet("strlink","Storage Inbox",Index.class) {
                   protected BookmarkablePageLink getBookmarkablePageLink() {
                        BookmarkablePageLink bookmarkablePageLink=   super.getBookmarkablePageLink(){
                             protected void onBeforeRender() {
                                  super.onBeforeRender();
                        return bookmarkablePageLink;
              });the second block of code does not compile please explain me why and what is the workaround ? i can override a method on a object when I initialize with new but cannot override if I get the object from super or somebody constructs why ?

    miro_connect wrote:
    in my case is there way to copy object returned from super to object created in sub and override methods ?Perhaps. You need to know about the implementation of the original object.

  • Some generic anonymous class overriding methods compile, while others don't

    I have the following (stripped-down) code. The abstract class SessionHandler<T> is used by other code to define and run an operation that needs a session to something. This is best done in my code with anonymous classes, because of the shear number of operations defined. In the EntityOps<T> class, these work great. But, in the last class shown here, SomeClass, the anonymous class definition fails, though the semantics are almost identical. (List<T> vs.List<AnotherClass>) What am I doing wrong here? Or is this a bug in Java?
    Thanks, Tom
    public interface IEntityOps<T> {
        T get();
        List<t> getAll();
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
        public final T perform() {
            ... calls handle(session) ...
    // These anonymous class definitions compile fine!
    public class EntityOps<T> implements IEntityOps<T> {
        public T get() {
            T ret = null;
            ret = new SessionHandler<T>() {
                T handle(Session s) throws Throwable {
                    T ret = (some T object calculation);
                    return ret;
            }.perform();
            return ret;
        public List<T> getAll() {
            T ret = null;
            return new SessionHandler<List<T>>() {
                List<T> handle(Session s) throws Throwable {
                    List<T> ret = (some List<T> calculation);
                    return ret;
            }.perform();
    // This anonymous class definition fails with the error:
    // "SomeClass.java": <anonymous someMethod> is not abstract and does not override abstract method handle()
    //     in SessionHandler at line XX, column XX
    public class SomeClass {
        public List<AnotherClass> someMethod() throws {
            List<AnotherClass> ret = null;
            ret = new SessionHandler<List<AnotherClass>>() {
                List<AnotherClass> handle(Session s) throws Throwable {
                    List<AnotherClass> ret = (some List<AnotherClass> calculation);
                    return ret;
            }.perform();
            return ret;
    }

    I added @Override above the abstract method override, and it provides this additional error:
    "HousingConfigImpl.java": method does not override a method from its superclass at line 382, column 17
    I have also reconstructed the code layout in a separate set of classes that have no dependancies, but there's no error coming from these!
    public class CustomThing {
    public interface ISomeInterface<T> {
        List<T> interfaceMethod();
    public abstract class SomeAbstractClass<T> {
        private Class _c = null;
        public SomeAbstractClass(Class c) {
            _c = c;
        protected Class getC() {
            return _c;
        public abstract T methodToOverride(Object neededObject) throws Throwable;
        public final T finalMethod() {
            try {
                return methodToOverride(new Object());
            } catch(Throwable e) {
                throw new RuntimeException(e);
    import java.util.List;
    import java.util.Collections;
    public class SomeInterfaceImpl<T> implements ISomeInterface<T> {
        public List<T> interfaceMethod() {
            return new SomeAbstractClass<List<T>>(CustomThing.class) {
                public List<T> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    import java.util.Collections;
    import java.util.List;
    public class SomeOtherClass {
        public List<CustomThing> someMethod() {
            return new SomeAbstractClass<List<CustomThing>>(CustomThing.class) {
                public List<CustomThing> methodToOverride(Object neededObject) throws Throwable {
                    return Collections.emptyList();
            }.finalMethod();
    }So, there's something about my code that causes it to be, somehow, different enough from the example provided above so that I get the error. The only differences in the override method definitions in my actual code are in the return type, but those are different in the example above as well. Here are the class declarations, anonymous abstract class creation statements, and abstract method declarations from the actual code.
    public abstract class SessionHandler<T> {
        abstract T handle(Session session) throws Throwable;
    public class EntityOps<T> implements IEntityOps<T> {
                return new SessionHandler<List<T>>(_mgr, _c, "getAll" + _c.getName()) {
                    List<T> handle(Session s) throws Throwable {
    public class HousingConfigImpl implements IHousingConfigOperations, ISessionFactoryManager {
                ret = new SessionHandler<List<Tenant>>((ISessionFactoryManager)this, Housing.class, "getTenantsInNeighborhood") {
                    List<Housing> handle(Session s) throws Throwable {I can't for the life of me see any syntactical difference between my example and the real code. But, one works and the other doesn't.

  • ER: Override Methods feature should detect anonymous inner class scope

    Hi,
    Given the following code:
    public class Class1 {
        public static void main(String[] args) {
            Thread t = new Thread() {
                // line 4
            t.start();
    }When the cursor is placed on line 4, activating the Override Method dialog (Source menu), should show Thread methods that I can override, in addition to Object methods. Currently only the method from class Object are being shown. The same treatment should also apply to local method inner classes. This happens with the latest 11g preview 3, and all previous versions.

    Hi,
    I'll file an ER
    Frank

  • How does polymorphism work during overriding methods?

    Is there any example code to explain polymorphism whne overriding methods.

    > I suppose; however, I've read that overloading
    can be
    considered basically just a naming "trick". Ifyou
    extend a class and add a new method with a newname
    it isn't considered polymorphism.
    Overloading != Overriding.
    I'm pretty sure you know this, so I'm assuming you
    misread the subject. :o)
    ~You assume correctly. Ignore everything I said - Monday, tired, raining, <insert other excuse here>.
    Look at that, 1 post from 2000.
    Message was edited by:
    jbish

  • Polymorphism & Overriding Methods

    Hello all,
    I'm creating a set of objects and trying to achieve polymorphism. However, I've run into some problems with the principles of overriding methods. My class structure is as follows (using pseudocode);
    BaseClass
    - Subclass1
    - Subclass2
    class BaseClass{
    abstract Object get();
    abstract void set(Object);
    class Subclass1 extends BaseClass{
    String get(){ return String; }
    void set(String){ this.String = String; }
    class Subclass2 extends BaseClass{
    Boolean get() { return Boolean; }
    void set(Boolean){ this.Boolean = Boolean; }
    The problem is that the subclasses are capable of setting and returning objects of different types. In order to get the polymorphic behavior I'm looking for, what do I need to do? Should I remove the abstract methods in the baseclass? Should I leave the abstract methods in the baseclass and change the methods in the subclasses?
    Please advise,
    R. Alcazar

    I think the following change will get you what you want:
    class BaseClass{
      abstract Object get();
      abstract void set(Object);
    class Subclass1 extends BaseClass{
      Object get(){ return String; }
      void set(Object){ this.String = (String)Object; }
    class Subclass2 extends BaseClass{
      Object get() { return Boolean; }
      void set(Object){ this.Boolean = (Boolean)Object; }
    }You may also want to check the class of the object in set to catch any errors.
    Jon
    Do you know of a Java job in Orange County, California?
    If so then please contact me: "http://home.pacbell.net/jswinth/Resume.htm"

  • What is happening overriding method  in JVM

    1.what is happeining in JVM while i do overriding method ?
    2. why we cant create object for abstract class. what is happeining in JVM?
    HOW TO I KNOW internal process of JVM above i mentioned . is there any book for this?

    There's plenty of information in the Java Virtual Machine specification available here on this web site.
    http://java.sun.com/docs/books/jvms/second_edition/html/Compiling.doc.html#14787
    regards,
    Owen

  • What's the difference between this and super in this class

    public interface Doggie {
    public void wao();
    public void fetchBall();
    public void run();
    public void sleep();
    public class Kittie {
    public void miao() {
    public void catchRat() {}
    public void run() {}
    public void sleep() {}
    public class KtoD extends Kittie implements Doggie {
    public void wao() {
    this.miao();//here super.miao() will work too,
    //what is the difference between them?
    public void fetchBall() {
    this.catchRat();//here too
    public void run() {
    super.run();
    public void sleep() {
    super.sleep();
    }

    well, just off the top of my head (someone who wants to quote the relevant parts of the JLS can reply here too) - this makes sense, because your KtoD class extends Kittie, which has a miao method. You've not overridden this method, so KtoD's miao method is Kittie's method. Thus, this.miao() and super.miao() refer to the same method. If you had overridden this method in your KtoD class then this.miao() would refer to the overridden miao method, and if you had wanted to call the miao method from Kittie then you would have had to use super.miao()
    Did that answer your question?
    Lee

  • Installing MP,DP and SUP in DMZ for IBCM

    Hi all,
    I would like start installing MP, DP and SUP role in my DMZ to support IBCM. My DMZ is in the same forest but in different and untrusted domain. The primary site and Enterprise Root Certificate (CA) are in the same domain (intranet). An admin account
    has been created in DMZ domain so the above roles can be installed from primary site server. I am still not too sure how I will install Cert that I created on root CA that is on intranet. Do I need to export it from Intranet and import back on the new site
    server in DMZ or use a different method?
    If the question is too confusing then please give your experience as how you have installed certificate on your site server (DMZ) for IBCM?
    Are you using primary server computer account for installing site roles in DMZ or a user account?
    Do I need to publish site information in DMZ domain as well?
    Thanks

    "My DMZ is in the same forest but in different and untrusted domain"
    This is not possible. By definition, all domains in a forest trust each other -- maybe not directly, but they do trust each other.
    Also, the new system in the DMZ will not be a "site server", it will be a site system (sometime called a site system server but not usually). This may seem like semantics, but its very important because "site server" means something very
    specific which the site system in the DMZ is not.
    Deploying certs in the DMZ can be done in one of many ways. You really should get a PKI smart person involved though because it's not ConfigMgr task. There are ways to deploy certs cross-domain and cross-forest using group policy auto-enrollment but these
    take setup and configuration on the PKI side. Alternatively you could use web enrollment on your CA is it is setup and has the proper templates available -- once again, that will take setup and configuration on your PKI. Finally, you could just use the command-line
    assuming the cert templates are accessible for the system in the other domain.
    For your scenario, you should be able to grant the site server's computer account local admin permissions on the DMZ site system. Don't forget about the FSP which can be very valuable for IBCM but will require and additional site system because it must be
    left to listen for HTTP traffic.
    Finally, publishing site information to the domain allows clients to locate the MP on the intranet however your clients won't be on the intranet to use location information, so that wouldn't help much. Additionally, clients use global catalog queries to
    perform their site location so within a forest, there is no need to publish the same informatin to mutliple domains (unless you have multiple sites which you do not).
    Jason | http://blog.configmgrftw.com | @jasonsandys

  • Self and super

    Hi developers,
    I would like to know if anyone knows of some good site(s) and/or book(s) that explain(s) the meaning of SELF and SUPER (with respect to Objective-C) as I myself am a newbie to the superset of the C language and find it confusing to understand what SELF and SUPER do.
    Cheers
    PS: I also posted the same message on the other forum (S/W Dev 101)

    Firstly, thanks for the replies so far
    Below are the header and implementation files for "MyViewController";
    Questions:
    1) In the instance method "viewDidUnload", why is "self" used and not in "dealloc" or for ToggleIsOn in the buttonPressed method ?
    I understand what you are saying about "super" in the "dealloc" method.
    2) Is it necessary to set the outlets to nil in the "dealloc" method ?
    3) Are "viewDidUnload" and "dealloc" correct programmatically speaking ?
    //-- MyViewController.h --
    #import <UIKit/UIKit.h>
    @interface MyViewController : UIViewController
    IBOutlet UIButton *myButton;
    IBOutlet UILabel *display;
    BOOL ToggleIsOn;
    float delayTime;
    @property (nonatomic, retain) IBOutlet UIButton *myButton;
    @property (nonatomic, retain) IBOutlet UILabel *display;
    -(IBAction)buttonPressed:(UIButton *)sender;
    @end
    //-- MyViewController.m --
    #import "MyViewController.h"
    @implementation MyViewController
    @synthesize myButton, display;
    -(IBAction)buttonPressed:(UIButton *)sender
    UIButton *button = sender;
    ToggleIsOn = !ToggleIsOn;
    NSLog(@"Button Pressed!");
    NSLog(@"Button Tag is %i", button.tag);
    NSLog(@"Button State is %i", button.state);
    NSLog(@"ToggleIsOn = %i", ToggleIsOn);
    display.text = (ToggleIsOn) ? @"Toggle ON" : @"Toggle OFF";
    // rest of instance method...
    -(void)viewDidUnload
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.myButton = nil;
    self.display = nil;
    -(void)dealloc
    [[myButton release]];
    myButton = nil;
    [[display release]];
    display = nil;
    [[super dealloc]];
    @end

  • Super wide Zoom and Super telephoto Zoom for 6D without vignette effect

    I have a Canon 6D Full frame camera. And I just bought the 24- 70 L II USM lens. 
    To complete my kit, I'm looking to invest a super wide zoom ( as low as 10 going uptil 22/ 24 mm) and super telephoto above 70 mm going uptil 300 mm (both preferably L series USM, with wide openings along the full focal range) 
    Before I make the purchases I want to be sure which lenses do NOT have the problem of vignetting AT ALL. 
    I am okay with barell distorition on the wide. But vignetting is something I want to totally avoid. 
    All you experienced folks out there, please guide me. Would also appreciate any links to lists that enumerate the same. 
    Alternatively I am also open to using prime lenses, but they are really low on my preference. 
    Appreciate your time and response. 

    In most software that allows you to add in some vignetting, you can also subtract it.  
    Some apps have lens profiles so they know how much vignetting occurs with that specific lens and at various focal lengths.
    But you can also do this manually.  In astro imaging we calls these images "flats".  The purpose of a "flat" is to determine how much vignetting there is in an image so that we can correctly adjust for it using a program like Photoshop.  
    To create a "flat" you would cover the lens with a piece of white translucent fabric.  Put some light on the fabric so that the fabric itself is evenly lit.  This means the view through the camera is basically just an all-white field with no contrast or features.   Then take a photo (it doesn't matter that the camera cannot focus on the fabric.)
    What you'll get is an all-white image typically brighter in center and dimmer toward the edges but the image can be used to measure the lens' specific vignetting (and in the case of a zoom that level of vignetting would vary by focal length.)  The image can be used as a reference image with software to completely eliminate vignetting.
    A photographer would normally not go to such extremes to get a perfectly flat field (lighting wise), but astro-imagers have to do this as a matter of routine.
    Tim Campbell
    5D II, 5D III, 60Da

  • I had all my old home video's and super 8 movies converted to DVD's. Since I will move back to Europe I asked the company to convert them to PAl system.

    I had all my old home video's and super 8 movies converted to DVD's. Since I will move back to Europe I asked the company to convert them to PAl system. I just got all the DVD's for a lot of money, but I can not play any of them on my MAC book.(I think that is because they were burned on zone 1 dvd's and my lap top works with zone 2.
    I wonder how I can make them work on my macbook..? I intended to start editing those movies so I need to be able to play them on my mac. Is there a way to copy them to zone 2 DVD's and or to zone 0 dvd's and where do I get those free zone or zone 1 recordable dvd's?
    ireen 1 min ago

    Welcome to the Apple Community.
    The Apple TV 2 will play all the content in your iTunes library that your Apple TV 1 does. It can no longer sync any of it but can stream it all just as the older model did. Airplay is a different feature that lets you stream from an iPad/iPhone, the Apple TV 2 has Airplay the first didn't.
    You can still sort and search content by genre, it still marks content watched and unwatched and mainly still lets you organise much as the Apple TV 1 did, with one exception. It doesn't do nested folders, so the ability to tag a movie as a show (ie James Bond) and have all the associated movies in a James bond folder has gone and it lists all these movies individually.
    It has a similar situation with TV shows. It will put all TV shows in a series in a folder as the older one did, but the new one lists each series separately whereas the older model would put all the series in one folder.
    Not nesting folders is a bit of a pain with large libraries and whilst I don't like it, it's more or less the only compromise I have to make and of course I get additional features too.

  • Override Company and Cost Center for FI Posting from HR Payroll

    Hello all. I have this scenario with a company that was merged into another and retroactive payroll occurs for absences and extra time in the "old" company, but the "old" merged company is closed so no postings can occur.
    I also found this unanswered post:  How to Override Company and Cost Center for FI Posting from HR Payroll
    We suppose that retroactive differences could be accounted in the new company code but I didnu2019t found any way to do it even in the BADI SMOD_PCPO0001 I couldnu2019t find a way to change the company code/cost center....
    Does anyone have dealt with the same problem? What is the solution?

    Amosha, thank you for your response.  Here is PCP0 that shows what I mean by 'header company code' that I don't see how to change (I re-ran pd 26 2008--bi-weekly payroll, btw):
    06/30/2009 Posting Document
    Run                      0000002791
    Company Code    0057
    Document            0000008174
    PostingCurrency  USD
    Reference           HRPAY00009
    Doc. Type            ZB
    Run Type             PP
    Posting Date        12/01/2008
    Documant Type   G/L Account Document   
    Document Date    06/30/2009
    Bus. Transaction HRP1
        There are error messages for this document
    Account Number with Text
    21301000   Accrued Salaries & Wages   CCTR 14515      ...
    20303998   HR P/R Doc Split                                               ...
    Messages for Document 000008174
    Error in document: HRPAY 0000008174
    The CO account assignment object belongs to company code 0001, not 0057
    Company code 0057 is now closed and has been merged into 0001.  Cost center 14515 in the above doc was populated by my clone of RPCIPE00 and call to my BAdI which retrieved current company and cost center from PA0001.  You can see from above that the 'header' data still shows 0057 and indeed, my version of RPCIPE00 only changes P_ITEM-BUKRS, P_ITEM-KOSTL and P_ITEM-SGTXT.  It looks to me that fm HRPP_TRANSLATE_FICO gets the 'header' company code afresh.  I was planning to leave WPBP-BUKRS (and all other Payroll data) alone (ie, not override company code).
    As for your other question, we post retros to /551 and /552. 
    Thanks again.

Maybe you are looking for