A non abstract child class must implement all pure virtual function of  parent abstract class in c++

Hi,
In Indesign SDK there is a class  IActionComponent having two pure virtual functions:
virtual void
UpdateActionStates(IActiveContext* ac, IActionStateList *listToUpdateGSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil) = 0;
virtual void
DoAction(IActiveContext* ac, ActionID actionID, GSysPoint mousePoint = kInvalidMousePoint, IPMUnknown* widget = nil)= 0;
But, the child class
class WIDGET_DECL CActionComponent : public IActionComponent
implements only UpdateActionStates function and not DoAction function.
There is no compilation error and the code is running fine..HOW
Can some one please explain me?

Oops!!! there is a small correction in my C++ program. The JunkMethod is being called from the constructor...like the following code.
#include <iostream.h>
#include <stdlib.h>
class Base
    public:
        Base()
            cout<<"In Base Class constructor..."<<endl;
            JunkMethod();
        void JunkMethod()
            TestAbsFunc();
        virtual void TestAbsFunc()= 0;
class TestAbstract:public Base
    public:
        TestAbstract()
            cout<<"In Extend Class constructor..."<<endl;
        void TestAbsFunc()
            cout<<"In TestAbsFunc...."<<endl;
int main()
      TestAbstract test;
      return 0;
}You can see the change in the constructor of the Base class. JunkMethod is being called, just to bluff the compiler to call the virtual method (so that it won't crib saying that abstract method cannot be called from the constructor). When Java is supporting this functionality without giving any errors, C++ gives errors when you call an abstract method from the constructor or fails to execute when I do some work around like this. Isn't it a drawback of abstract funcationality supported by C++ (I'm not sure if it's a drawback or not)
Regards,
Kalyan.

Similar Messages

  • "Bean Class Must Implement X" message, but bean class does implement X

    When trying to deploy an .ear file on WebLogic 9.0 that contains an MDB EJB, I get a message like the following:
    In EJB ITS-MDB(Application: ITSNO,
    EJBComponent: ITSMDB.jar), the bean class must implement
    its.common.TelnetMessageListener. '
    The ITS-MDB EJB class (its.mdb.TelnetMessageListenerImpl) referenced in ejb-jar.xml DOES implement its.common.TelnetMessageListener, and both .class files exist in the same .jar file.
    (The TelnetMessageListener interface extends javax.ejb.MessageDrivenBean.)
    This .ear deploys without a problem on Oracle's OC4J and IBM's Websphere, so it appears that there is some Weblogic peculiarity (a bug, a different spec interpretation, etc.) causing the problem.
    This problem is happening on Weblogic 9.0 using Java 1.5.0_03 on Windows XP.
    Any ideas why this might be happening?

    Thanks for the suggestion, Rob.
    I checked to ensure that no out-dated TelnetMessageListenerImpl and TelnetMessageListener were being used. It looks like I am not using older versions.
    I first checked the classpath specified by the log, and did not see anywhere in there that would contain either of these classes.
    To be sure, I then decided to remove each class from the jar file and attempt to deploy it. If it succeeded, that would mean there was some other version of that file on the classpath.
    I first removed TelnetMessageListenerImpl from ITSMDB.jar, and then tried deploying it. As expected, I received the following message:
    Unable to deploy EJB: C:\bea\user_projects\domains\domain_good\.\servers\AdminServer\tmp\_WL_user\ITSNOMinus\fvdi9g\ITSMDB.jar from ITSMDB.jar:
    Unable to load a class specified in your ejb-jar.xml: its.mdb.TelnetMessageListenerImpl
         at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:371)
         at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:90)
    I then replaced TelnetMessageListenerImpl and attempted to remove TelnetMessageLister. I got a slightly different (but essentially the same) error:
    java.lang.NoClassDefFoundError: oracle/wireless/its/common/TelnetMessageListener
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at weblogic.utils.classloaders.GenericClassLoader.defineClass(GenericClassLoader.java:302)
         at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:255)
         at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:223)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:158)
         at weblogic.ejb20.deployer.EJBModule.setupEJBToImplClassDependencies(EJBModule.java:1396)
    Here is the exception stack I get will the original ITSNO deployment:
    ####<Sep 20, 2005 11:20:57 AM PDT> <Info> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240457892> <BEA-149059> <Module ITSMDB.jar of application ITSNO is transitioning from STATE_NEW to STATE_PREPARED on server AdminServer.>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Info> <EJB> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458002> <BEA-010008> <EJB Deploying file: ITSMDB.jar>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Info> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458080> <BEA-149061> <Module ITSMDB.jar of application ITSNO failed to transition from STATE_NEW to STATE_PREPARED on server AdminServer.>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Info> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458080> <BEA-149059> <Module ITSRA.rar of application ITSNO is transitioning from STATE_PREPARED to STATE_NEW on server AdminServer.>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Info> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458111> <BEA-149060> <Module ITSRA.rar of application ITSNO successfully transitioned from STATE_PREPARED to STATE_NEW on server AdminServer.>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Error> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458158> <BEA-149265> <Failure occured in the execution of deployment request with ID '1127240456080' for task '0'. Error is: 'weblogic.application.ModuleException: Exception preparing module: EJBModule(ITSMDB.jar)
    Unable to deploy EJB: C:\bea\user_projects\domains\domain_good\.\servers\AdminServer\tmp\_WL_user\ITSNO\x5gd0k\ITSMDB.jar from ITSMDB.jar:
    In EJB ITS-MDB(Application: ITSNO, EJBComponent: ITSMDB.jar), the bean class must implement its.common.TelnetMessageListener.
    weblogic.application.ModuleException: Exception preparing module: EJBModule(ITSMDB.jar)
    Unable to deploy EJB: C:\bea\user_projects\domains\domain_good\.\servers\AdminServer\tmp\_WL_user\ITSNO\x5gd0k\ITSMDB.jar from ITSMDB.jar:
    In EJB ITS-MDB(Application: ITSNO, EJBComponent: ITSMDB.jar), the bean class must implement its.common.TelnetMessageListener.
         at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:371)
         at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:90)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:318)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:53)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:43)
         at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:236)
         at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:147)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:61)
         at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:191)
         at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:84)
         at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:197)
         at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:724)
         at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1137)
         at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:224)
         at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:109)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:166)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:12)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:54)
         at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
    In EJB ITS-MDB(Application: ITSNO, EJBComponent: ITSMDB.jar), the bean class must implement its.common.TelnetMessageListener.
         at weblogic.ejb20.deployer.MessageDrivenBeanInfoImpl.initializeOnMessageMethodInfo(MessageDrivenBeanInfoImpl.java:593)
         at weblogic.ejb20.deployer.MessageDrivenBeanInfoImpl.<init>(MessageDrivenBeanInfoImpl.java:346)
         at weblogic.ejb20.deployer.BeanInfoImpl.createBeanInfoImpl(BeanInfoImpl.java:551)
         at weblogic.ejb20.deployer.MBeanDeploymentInfoImpl.initializeBeanInfos(MBeanDeploymentInfoImpl.java:597)
         at weblogic.ejb20.deployer.MBeanDeploymentInfoImpl.<init>(MBeanDeploymentInfoImpl.java:221)
         at weblogic.ejb20.deployer.EJBDeployer.prepare(EJBDeployer.java:1165)
         at weblogic.ejb20.deployer.EJBModule.prepare(EJBModule.java:344)
         at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:90)
         at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:318)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:53)
         at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:43)
         at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615)
         at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
         at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:236)
         at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:147)
         at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:61)
         at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:191)
         at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:84)
         at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:197)
         at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:724)
         at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1137)
         at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:224)
         at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:109)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:166)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:12)
         at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:54)
         at weblogic.work.ServerWorkManagerImpl$WorkAdapterImpl.run(ServerWorkManagerImpl.java:518)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
    >
    ####<Sep 20, 2005 11:20:58 AM PDT> <Warning> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458252> <BEA-149004> <Failures were detected while initiating distribute task for application 'ITSNO'.>
    ####<Sep 20, 2005 11:20:58 AM PDT> <Warning> <Deployer> <jrozier-pc> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1127240458252> <BEA-149078> <Stack trace for message 149004
    There are a few other updates since my first post as well:
    (1) I get the same message when I try to deploy just ITSMDB.jar as an application as I do when I try to deploy my ITSNO.ear (which contains both an RA and the MDB).
    (2) This same application now also works on JBoss. (I had to add a jboss.xml to tell the MDB about the RA.)
    (3) I fixed the ejb-jar.xml container-transaction element to refer to ITS-MDB (with a dash) instead of ITS_MDB (with an underscore). (This fix goes to show that some containers are more forgiving than others--OC4J and Websphere did not complain about it, but JBoss gave an error message and would not deploy until this was fixed.)

  • Making all named member functions of an actionscript class avlbl to ExternalInterface automatically

    Making all named member functions of an actionscript class available to ExternalInterface automatically :
    I am trying to custom-tweak the as3 compiler to generate instructions to register all functions in the ClassDefinitionNode to ExternalInterface.
    I guess the operation will have to be performed somwhere between the analyze sequences of the compiler, but am not quite able locate where.
    I have this codelet (executed for all constructors, for every non-constructor)
                    ArgumentListNode argListNode = new ArgumentListNode(
                            new LiteralStringNode(
                                    NodeMagic.getClassName(clNode)+ "." + functionCommonNode.identifier.name), 0);
                    //argListNode.items.add(new LiteralNullNode());
                    argListNode.items.add(new IdentifierNode(functionCommonNode.identifier.name, 0));
                    MemberExpressionNode mnode = new MemberExpressionNode(new IdentifierNode("ExternalInterface", 0),
                            new InvokeNode("addCallback",
                                    argListNode),0);
                    mnode.ref = new ReferenceValue(cx, null, "ExternalInterface", ObjectValue.intrinsicNamespace); //NOT TOO SURE ABOUT THIS ONE
                    constructor.body.items.add(mnode
    Any assistance would be appreciated!
    Thanks!

    Making all named member functions of an actionscript class available to ExternalInterface automatically :
    I am trying to custom-tweak the as3 compiler to generate instructions to register all functions in the ClassDefinitionNode to ExternalInterface.
    I guess the operation will have to be performed somwhere between the analyze sequences of the compiler, but am not quite able locate where.
    I have this codelet (executed for all constructors, for every non-constructor)
                    ArgumentListNode argListNode = new ArgumentListNode(
                            new LiteralStringNode(
                                    NodeMagic.getClassName(clNode)+ "." + functionCommonNode.identifier.name), 0);
                    //argListNode.items.add(new LiteralNullNode());
                    argListNode.items.add(new IdentifierNode(functionCommonNode.identifier.name, 0));
                    MemberExpressionNode mnode = new MemberExpressionNode(new IdentifierNode("ExternalInterface", 0),
                            new InvokeNode("addCallback",
                                    argListNode),0);
                    mnode.ref = new ReferenceValue(cx, null, "ExternalInterface", ObjectValue.intrinsicNamespace); //NOT TOO SURE ABOUT THIS ONE
                    constructor.body.items.add(mnode
    Any assistance would be appreciated!
    Thanks!

  • Error of pure virtual functions implement

    Pure virtual functions implement of base classes, such as:
    class IUnknown
    public:
        virtual uint32  AddRef()  = 0;
        virtual void    Release() = 0;
    class ITexture : public IGammaUnknown
    public:
        ........some other virtual functions......
    class CTexture
        : public ITexture
        , public CGraphicRes
    public:
         //implement in cpp
         virtual uint32  AddRef(){ ...... };
    sometimes report an undefined function when linking: undefined reference to AddRef.
    sometimes throw an error when calling AddRef: null function poniter called.

    sorry,the code is wrong.
    right code is here:
    class IUnknown
    public:
        virtual uint32  AddRef()  = 0;
        virtual void    Release() = 0;
    class ITexture : public IUnknown
    public:
        ........some other virtual functions......
    class CTexture
        : public ITexture
        , public CGraphicRes
    public:
         //implement in cpp
         virtual uint32  AddRef(){ ...... };
         virtual void    Release(){ ...... };
    sometimes report an undefined function when linking: undefined reference to AddRef.
    sometimes throw an error when calling AddRef: null function poniter called.

  • Design Question - Class Must Implement Interface

    I'm not sure how to describe this in summary, really. I'd say that I sort of want multiple inheritance, but I don't want to be shot. :-P So let me describe the situation:
    I have an interface, DataEditingComponent<T>. The idea is that anything implementing the interface is capable of allowing the user to edit an object of type T. For example, a DataEditingComponent<Integer> would allow the user to input an integer. A DataEditingComponent<Map<SomeObj,Integer>> might represent an object capable of editing a table describing the number of instances of SomeObj. You get the idea. DataEditingComponent<T> describes three methods: getEditingData():T, setEditingData(T):void, and getDefaultEditingData():T. I'm assuming you can guess what those do.
    Well, the practical application of this interface is in the use of a Swing application. It provides a very clean and standardized way of adjusting the contents of components which edit data. Obviously, a JTextField would work about as well as a DataEditingComponent<String>, but for more complicated components (DataEditingComponent<GameWorldMap>, for instance), the standardized interface is very helpful.
    Since in practice everything that ever implements DataEditingComponent<T> extends JComponent, it would be nice to declare this as a requirement somehow. However, given that JComponent is extended into a number of various subclasses, I can't just go making DataEditingComponent<T> an abstract subclass.
    So far, the only conclusion I've reached is that I can take each and every JComponent subclass and extend it into an abstract subclass which implements DataEditingComponent<T>... but that's very ugly and quickly leads to other problems. And presently, I'm left casting things from one to the other, with which I am also not happy.
    So... any way out of this? Have I done something wrong design-wise? Or am I just stuck in a language limitation?
    Thanks for reading!

    I'm not sure how to describe this in summary, really.
    I'd say that I sort of want multiple inheritance,
    but I don't want to be shot. :-P So let me
    describe the situation:
    I have an interface, DataEditingComponent<T>. The
    idea is that anything implementing the interface is
    capable of allowing the user to edit an object of
    type T. For example, a DataEditingComponent<Integer>
    would allow the user to input an integer. A
    DataEditingComponent<Map<SomeObj,Integer>> might
    represent an object capable of editing a table
    describing the number of instances of SomeObj. You
    get the idea. DataEditingComponent<T> describes
    three methods: getEditingData():T,
    setEditingData(T):void, and
    getDefaultEditingData():T. I'm assuming you can
    guess what those do.
    Well, the practical application of this interface is
    in the use of a Swing application. It provides a
    very clean and standardized way of adjusting the
    contents of components which edit data. Obviously, a
    JTextField would work about as well as a
    DataEditingComponent<String>, but for more
    complicated components
    (DataEditingComponent<GameWorldMap>, for instance),
    the standardized interface is very helpful.
    Since in practice everything that ever implements
    DataEditingComponent<T> extends JComponent, it would
    be nice to declare this as a requirement somehow.
    However, given that JComponent is extended into a
    number of various subclasses, I can't just go making
    DataEditingComponent<T> an abstract subclass.
    So far, the only conclusion I've reached is that I
    can take each and every JComponent subclass and
    extend it into an abstract subclass which implements
    DataEditingComponent<T>... but that's very ugly and
    quickly leads to other problems. And presently, I'm
    left casting things from one to the other, with which
    I am also not happy.
    So... any way out of this? Have I done something
    wrong design-wise? Or am I just stuck in a language
    limitation?Hmm. The component is part of the view. The data is part of the model. Putting them together seems to go against the whole Model-View-Controller concept. You may want to have a look at how Swing separates the editing from the rendering from the model for complicated widgets such as JTable. The editors hava methods such as getEditorComponent() which returns the Component used to edit the data. Everywhere you are currently adding DataEditingComponent instances to your GUI, you can instead call a getDataEditingComponent() method, which can require that the returned object is a JComponent.

  • Abstract Class that implements Comparable

    I am trying to understand how a comparable interface works with an abstract class. Any help is greatly appreciated.
    I have a class ClassA defined as follows:
    public abstract class ClassA implements Comparable I have a method, compareTo(..), within ClassA as follows:
    public int compareTo(Object o) I have a sub-class ClassB defined as follows:
    public class ClassB extends ClassAI am receiving a compile error:
    Class must implement the inherited abstract method packagename.ClassA.compareTo(Object)
    Should or can the compareTo be abstract in ClassA and executed in ClassB? Just not sure how this works.

    ???? if you are inheriting from an abstract class your subclass must implement methods that were declared in the parent (abstract) class but not implemented
    When in doubt, refer to the Java Language Specification..

  • How can a custom class call a function in "parent" class?

    Say I have an application (ultrasimplified):
    public class myApp {
    myClass mc;
    boolean foo=false;
    public static void main(String[] args) {
    mc = new myClass();
    public static void myFunc(boolean blah) {
    foo=blah;
    in a separate .java file where my questions lie:
    public class myClass {
    boolean bar=true;
    public void myClass() {
    // this is wrong, but how would I do this:
    foo = bar; // foo in myApp set to true
    // or how would I call "myFunc()" in myApp from this class:
    myFunc(bar);
    my problem is that I've created a new class that I share between two applications so I could share the code. However, I want this class I created to call a function in the application class that instanciated it. Or alternatively, I would like to set a variable in the class that instanciated myClass.
    How would go about this? I've used the "this" parameter in applets to pass the parent class to an inner class, but main() in applications doesn't allow the non-static "this":
    myClass my = new myClass(this);
    Is there something similar I can do?

    You can let MyApp implement an interface and refer to that object in MyClass:
    class MyApp implements Something {
    main() {
    MyApp app = new MyApp();
    MyClass mc = new MyClass(app);
    public void foo() { }
    class MyClass {
    Something app;
    MyClass(Something app) {
    this.app = app;
    app.foo();
    interface Something {
    public void foo();
    Better yet, you can let MyApp extend an abstract class that defines foo(). Then MyApp can override the foo() method. If later on, the abstract class needs to add a bar() method then default implementation can be done in the abstract class. If you make it an interface then all implementing classes will have to be updated to implement the new method.

  • Why a static class can implements a non-static interface?

    public class Test {
         interface II {
              public void foo();
         static class Impl implements II {
              public void foo() {
                   System.out.println("foo");
    }Why a static class can implements a non-static interface?
    In my mind, static members cann't "use" non-static members.

    Why a static class can implements a
    non-static interface?There's no such thing as a non-static member interface. They are always static even if you don't declare them as such.
    An interface defines, well, a public interface to be implemented. It doesn't matter whether it is implemented by a static nested class or by an inner class (or by any class at all). It wouldn't make sense to enforce that it should be one or the other, since the difference between a static and non-static class is surely an irrelevant detail to the client code of the interface.
    In my mind, static members cann't "use" non-static
    members.
    http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246026
    Member interfaces are always implicitly static. It is permitted but not required for the declaration of a member interface to explicitly list the static modifier.

  • The type must implement the inherited abstract method???

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.ActiveEvent;
    import java.applet.*;
    public class MoveIt extends Applet implements ActionListener
         private Image cup;
         private Panel keyPad;
         public int yaxis = 15;
         public int xaxis = 15;
         private Button keysArray[];
         public void init()
              cup = getImage(getDocumentBase(), "cup.gif");
              Canvas myCanvas = new Canvas();
              setBackground(Color.blue);
              setLayout(new BorderLayout());
              Button up = new Button("Up");
              Button down = new Button("Down");
              Button right = new Button("Right");
              Button left = new Button("Left");
              Button center = new Button("Center");
              add(myCanvas, BorderLayout.NORTH);
              add(keyPad, BorderLayout.SOUTH);
              keyPad.add(up, BorderLayout.NORTH);
              up.addActionListener(this);
              keyPad.add(down, BorderLayout.SOUTH);
              down.addActionListener(this);
              keyPad.add(right, BorderLayout.EAST);
              right.addActionListener(this);
              keyPad.add(left, BorderLayout.WEST);
              left.addActionListener(this);
              keyPad.add(center, BorderLayout.CENTER);
              center.addActionListener(this);
         public void paint( Graphics g )
              g.drawImage( cup, xaxis, yaxis, this );
         public void ActionPerformed(ActionEvent e)
              String action = e.getActionCommand();
              if(action.equals("Up"))
                   yaxis = yaxis - 15;
              if(action.equals("Down"))
                   yaxis = yaxis + 15;
              if(action.equals("Left"))
                   xaxis = xaxis - 15;
              if(action.equals("Right"))
                   xaxis = xaxis + 15;
              if(action.equals("Center"))
                   xaxis = 125;
                   yaxis = 60;
    }How come there is an error:
    The type MoveIt must implement the inherited abstract method
    ActionListener.actionPerformed(ActionEvent)
    What the hell does that mean?

    A class that implements an interface must define the methods of the interface. Your applet (or the one you borrowed) states at the top that it implements the ActionListener interface. If you go to the API, you'll see that this interface declares a method "actionPerformed", and so this class must have a method that matches the one in the interface. I see that your applet will have some Buttons. You'll need an actionPerformed method if you want the buttons to use your class (this) as their action listener.
    Edit: I see that you already have an "ActionPerformed" method, but note that case matters, and this is not the same as "actionPerformed". Change one letter and you're on your way.
    Edited by: Encephalopathic on Jan 15, 2008 8:44 PM

  • Abstract Method in a Class with implemented method

    I have a class which already has methods Implemented.I mean thse metgods are not abstract.I want only one method to be abstarct which will be overrideen by its subclass or derived Class
    I have never tried this
    Does anyone knows how to do this
    If yes could you give me syntax of the method
    Thanks in advance
    CSJakharia

    javax.swing.JComponent is an example of an abstract
    class with no abstract methods. That is why the
    following works:
    JComponent component = new JComponent(){};
    Not to forget you cannot instantiate abstarct classes
    public abstract class Test
    public String getName()
    return "Mike";
    public static void main(String[] args)
    Test tt = new Test();
    System.out.println(tt.getName());
    }and you would get the error
    The type Test cannot be instantiated.
    You remove the abstract keyword and it would compile
    good.No I am not misinterpreting I know what he is saying but I am closing the door of misinterpretation which I felt was possible. ;)
    cheers

  • How to find out in program which all classes have implemented an interface

    Hello,
    I have created an interface and few classes are implementing the interface.
    I want to know in a program which all class have implemented the interface.
    Is it possible to find it out and how?
    Regards,
    Bikash.

    Hi Bikash,
    Read the Database view VSEOIMPLEM with where condition REFCLSNAME = Interface Name and version = 1.
    This would give you all the classes which have implemented the interface and are active...
    If you want to look at the values that the field version can have then see Type Group SEOC ans search for version....
    Hope this help...
    Regards,
    Sitakant

  • Concrete classes implement abstract class and implements the interface

    I have one query..
    In java collection framework, concrete classes extend the abstract classes and implement the interface. What is the reason behind extending the class and implementing the interface when the abstract class actually claims to implement that interface?
    For example :
    Class Vector extends AbstractList and implements List ,....
    But the abstract class AbstractList implements List.. So the class Vector need not explicitly implement interface List.
    So, what is the reason behind this explicit definition...?
    If anybody knows please let me know..
    Thanx
    Rajendra.

    Why do you post this question again? You already asked this once in another thread and it has been extensively debated in that thread: http://forum.java.sun.com/thread.jsp?forum=31&thread=347682

  • Provider must implement the class 'System.Web.Security.RoleProvider'.

    Hi I am implementing Membership and roles security on ASP .NET 4.0 site using oracle database. Have already configured my web.config file to use oraclemembershipprovider and oracleroleprovider but whenever I am trying to create a role or a user through "Web Site Administration Tool" I get this error "Provider must implement the class 'System.Web.Security.RoleProvider'" it comes as soon as I click on create user or create/manage role links.
    btw I also noticed that there is was no row in my "ora_aspnet_applications" table I manually added one line and have already given the application name which matches with web.config entry
    Any help will be appreciated, is there something wrong with my installation? Also I am using latest version of ODAC.
    Saadie
    Edited by: user13546761 on Jan 8, 2011 9:04 AM

    errr okay my bad, there was a typo in web.config

  • Force Derived Class to Implement Static Method C#

    So the situation is like, I have few classes, all of which have a standard CRUD methods but static. I want to create a base class which will be inherited so that it can force to implement this CRUD methods. But the problem is, the CRUD methods are static. So
    I'm unable to create virtual methods with static (for obvious reasons). Is there anyway I can implement this without compromising on static.
    Also, the signature of these CRUD methods are similar.
    E.g. ClassA will have CRUD methods with these type of Signatures
    public static List<ClassA> Get()
    public static ClassA Get(int ID)
    public static bool Insert(ClassA objA)
    public static bool Update(int ID)
    public static bool Delete(int ID)
    ClassB will have CRUD signatures like
    public static List<ClassB> Get()
    public static ClassB Get(int ID)
    public static bool Insert(ClassB objB)
    public static bool Update(int ID)
    public static bool Delete(int ID)
    So I want to create a base class with exact similar signature, so that inherited derived methods will implement their own version.
    For E.g. BaseClass will have CRUD methods like
    public virtual static List<BaseClass> Get()
    public virtual static BaseClassGet(int ID)
    public virtual static bool Insert(BaseClass objBase)
    public virtual static bool Update(int ID)
    public virtual static bool Delete(int ID)
    But the problem is I can't use virtual and static due to it's ovbious logic which will fail and have no meaning.
    So is there any way out?
    Also, I have few common variables (constants) which I want to declare in that base class so that I don't need to declare them on each derived class. That's why i can't go with interface also.
    Anything that can be done with Abstract class?

    Hi,
    With static methods, this is absolutely useless.
    Instead, you could use the "Singleton" pattern which restrict a class to have only one instance at a time.
    To implement a class which has the singleton pattern principle, you make a sealed class with a private constructor, and the main instance which is to be accessed is a readonly static member.
    For example :
    sealed class Singleton
    //Some methods
    void Method1() { }
    int Method2() { return 5; }
    //The private constructor
    private Singleton() { }
    //And, most importantly, the only instance to be accessed
    private static readonly _instance = new Singleton();
    //The corresponding property for public access
    public static Instance { get { return _instance; } }
    And then you can access it this way :
    Singleton.Instance.Method1();
    Now, to have a "mold" for this, you could make an interface with the methods you want, and then implement it in a singleton class :
    interface ICRUD<BaseClass>
    List<BaseClass> GetList();
    BaseClass Get(int ID);
    bool Insert(BaseClass objB);
    bool Update(int ID);
    bool Delete(int ID);
    And then an example of singleton class :
    sealed class CRUDClassA : ICRUD<ClassA>
    public List<ClassA> GetList()
    //Make your own impl.
    throw new NotImplementedException();
    public ClassA Get(int ID)
    //Make your own impl.
    throw new NotImplementedException();
    public bool Insert(ClassA objA)
    //Make your own impl.
    throw new NotImplementedException();
    public bool Update(int ID)
    //Make your own impl.
    throw new NotImplementedException();
    public bool Delete(int ID)
    //Make your own impl.
    throw new NotImplementedException();
    private CRUDClassA() { }
    private static readonly _instance = new CRUDClassA();
    public static Instance { get { return _instance; } }
    That should solve your problem, I think...
    Philippe

  • Abstract method which when implemented will have different parameters

    Hello to all,
    I have an assignment but not looking for someone to do it for me. I am only searching for a suggestion on how to do the following.
    Imagine having an application that needs to provide an estimate of the rent for different buildings.
    Basically I start with by having a class name Building. This class has an abstract method called estimateRent.
    I then create two classes that extend the class Building which are named Apartment and House. Both need to have the method estimateRent.
    However the problem is that the rent for the Apartment is calculated on the nights passed in the flat and the people in it, while the rent for the House is just calculated on a month bases.
    This means the estimateRent method requires to have different parameters depending if it is implemented inside the Apartment class or the House class.
    Now I only know of two options.
    The first option is to not declare the estimateRent method as an abstract method inside the Building class and just implemented inside the Apartment and House with different parameters. I do not like this option since in the future if a new Building comes in then I would like to impose the fact that that object needs to have a calculate method.
    The second option is to make the estimateRent method as abstract inside the Building class however takes a parameter of either a String array or else a Map. Then the estimateRent within the Apartment class would search for the elements tagged as nights and people, and the House class would only search for the elements tagged as months!
    However do not know if there are any other, better ways on how to do this. I am using Java 1.4 however if you only have answers for Java 5.0 then please post them again since I always like to learn something new :)
    Thank You for any comments.
    tx

    The implementation changes, yes.Yes that I could understand in the Strategy Pattern (in the document I read it was being compared with the Template Pattern).
    Then you need to refactor your design.I tought about that, however if you read my first post you will notice that I have different criteria on which the costs need to be estimated. While the costs for a flat are estimated on the people staying in and nights slept there, the costs for the house are based only on the months stayed there regardless of the people living in. Now for me I feel that it is bad programming practice to create one method that can have all the parameters required for any scenario. I mean the following is NOT something I am going to do:
    estimateCosts(int nights, int people, int months ... etc);
    That's not a very elegant way of going about it.
    What is the "Context" going to have?Yep I agree, but so far my limited brain has only come up with that! I am open to any other sugestion! always if i understand it first!
    Basically the Context would better be named as Criteria and it would be an interface as follows:
    interface Criteria{}
    Then I would create two classes that implement the Criteria object as follows:
    class AppartmentCriteria implements Criteria{
    public Result estimateCosts(int nights, int people);
    class HouseCriteria implements Criteria{
    public Result estimateCosts(int months);
    Now when I recieve the inputs, depending on the scenario the Criteria is typecasted and the correct parameters passed and we recieve the Result.
    I feel the above sucks since I am not seeing it as an object oriented way of doing this out! Is there any other sugestions! The refactoring thing I am intrested in! however really I can not see how such a call to that method could be refectored!
    Thank You,
    tx.
    PS: Sun has blocked my other account as well, and this time they did not even send me an email to confirm that I was registered successfuully :( Is there someone I can contact on this? I guess next time I will reply with tx53m :)

Maybe you are looking for