Calling a method from an abstract class in a seperate class

I am trying to call the getID() method from the Chat class in the getIDs() method in the Outputter class. I would usually instantiate with a normal class but I know you cant instantiate the method when using abstract classes. I've been going over and over my theory and have just become more confused??
Package Chatroom
public abstract class Chat
   private String id;
   public String getID()
      return id;
   protected void setId(String s)
      id = s;
   public abstract void sendMessageToUser(String msg);
Package Chatroom
public class Outputter
public String[] getIDs()
     // This is where I get confused. I know you can't instantiate the object like:
        Chat users=new Chat();
        users.getID();
I have the two classes in the package and you need to that to be able to use a class' methods in another class.
Please help me :(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

I have just looked over my program and realised my class names are not the most discriptive, so I have renamed them to give you a clearer picture.
package Chatroom
public abstract class Chatter
private String id;
public String getID()
return id;
protected void setId(String s)
id = s;
I am trying to slowly build a chatroom on my own. The Chatter class is a class that will be used to represent a single logged in user and the user is given an ID when he logs in through the setId and getID() methods.
package Chatroom;
import java.util.Vector;
public class Broadcaster
private Vector<Chatter> chatters = new Vector<Chatter>();
public String[] getIDs()
// code here
The Broadcaster class will keep a list of all logged-in users keeps a list of all the chats representing logged-in users, which it stores in a Vector.I am trying to use the getIDs() method to return an array of Strings comprising the IDs of all logged-in users, which is why im trying to use the getID() method from the Chat class.
I apologise if I come across as clueless, it's just I have been going through books for about 4 hours now and I have just totally lossed all my bearings

Similar Messages

  • Calling a method from a super class

    Hello, I'm trying to write a program that will call a method from a super class. This program is the test program, so should i include extends in the class declaration? Also, what code is needed for the call? Just to make things clear the program includes three different types of object classes and one abstract superclass and the test program which is what im having problems with. I try to use the test program to calculate somthing for each of them using the abstract method in the superclass, but its overridden for each of the three object classes. Now to call this function what syntax should I include? the function returns a double. Thanks.

    Well, this sort of depends on how the methods are overridden.
    public class SuperFoo {
      public void foo() {
         //do something;
      public void bar(){
         //do something
    public class SubFoo extends SuperFoo {
       public void foo() {
          //do something different that overrides foo()
       public void baz() {
          bar(); //calls superclass method
          foo(); //calls method in this (sub) class
          super.foo(); //calls method in superclass
    }However, if you have a superclass with an abstract method, then all the subclasses implement that same method with a relevant implementation. Since the parent method is abstract, you can't make a call to it (it contains no implementation, right?).

  • Need help calling a method from an immutable class

    I'm having difficulties in calling a method from my class called Cabin to my main. Here's the code in my main              if(this is where i want my method hasKitchen() from my Cabin class)
                        System.out.println("There is a kitchen.");
                   else
                        System.out.println("There is not a kitchen.");
                   }and here's my method from my Cabin class:public boolean hasKitchen()
         return kitchen;
    }

    You should first have an instance of Cabin created by using
       Cabin c = ....
       if (c.hasKitchen()) {
         System.out.println("There is a kitchen.");
       } else {
            System.out.println("There is not a kitchen.");
       }

  • Calling a method from another class... that requires variables?

    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
         cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), but I'm not sure how! I have tried, but then I get errors such as ')' expected?
    Any ideas! :D

    f1d wrote:
    I'm calling a method from another class to change the date (its a date object) in another class.
    I keep getting the error 'setDate(int,int,int) in Date cannot be applied to ()'
    My code is:
    public int changeDate()
    cycleDate.setDate();
    }I'm guessing I need to pass 3 parameters (day, month, year), seems that way from the error you posted
    but I'm not sure how!
    setDate(16, 6, 2008);
    I have tried, but then I get errors such as ')' expected?
    Any ideas! :Dyou need to post your code if you're getting specific errors like that.
    but typically ')' expected means just that, you have too many or not enough parenthesis (or in the wrong place, etc.)
    i.e. syntax error

  • Help on Calling a method from another class

    how can i call a method from another class.
    Class A has 3 methods
    i just want to call only one of these 3 methods into my another class.
    How can I do that.

    When i am trying this
    A a=new A;
    Its calling all the methods from class A. I just want
    to call a specfic method.How can it be done?When i am trying this
    A a=new A();
    Its calling all the methods from class A. I just want to call a specfic method.How can it be done?

  • Calling a method from another class or accessing a component from another

    Hi all
    im trying to make a find/replace dialog box
    my main application form has a jtextpane and when i open up the find and replace dialog box it has two textboxes (find and replace)
    now i have the code to do the finding on my jtextpane but how do i call that code to do the find method?
    I have tried having the code in my main application class but then how do i call that method from my dialog box class?
    ive also tried having the code in my dialog box class, but then how to i tell it to work on my jtextpane which is in my main ap class?

    well if someone had been nice enough to provide me
    with a tutorial i wouldnt have gotten into this
    muddle, no need to be rude is there!I'm not rude. And you also wouldn't have gotten into the muddle if you searched yourself. This site provides many very good tutorials about all kinds of stuff.
    http://java.sun.com/docs/books/tutorial/java/javaOO/classes.htmlAmong other things, it mentions that "static" defines everything that belongs to a class, as opposed to an object.

  • How to call a method from class interface

    Hi ,
    I want to call a method from a 'class interface' in a BADI .
    Class Interface -- /SAPSRM/CL_PDO_DO_BASE
    Method -- /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS
    Please let me know how can I call this method in my BADI.
    Thanks-

    Hi Harmeet,
    Follow these simple steps.
    1. Create an instance of class interface /SAPSRM/CL_PDO_DO_BASE if method /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS is instance method and
    call instance -> /SAPSRM/IF_PDO_DO_PARTNER_BASE~UPDATE_ITEM_PARTNERS
    2.if method /SAPSRM/IF_PDO_DO_PARTNER_BASEUPDATE_ITEM_PARTNERS is static method ,call directly using class interface like /SAPSRM/CL_PDO_DO_BASE=> /SAPSRM/IF_PDO_DO_PARTNER_BASEUPDATE_ITEM_PARTNERS.
    If you feel any dificulty in declaring instances and call methods, 
    Goto EDIT-> Pattern ->ABAP Object Patterns, Give class name , instance name and method, you got the required code.
    Thanks,
    Prasad.

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How to call a method from another class

    I have a problem were i have to call a method from another class. What is the command line that i have to use. Thanks.

    Here's one I wipped up in 10 minutes... Cool!
    package forums;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import krc.utilz.io.Filez;
    import java.io.FileNotFoundException;
    class FileDisplayer extends JFrame
      private static final long serialVersionUID = 0L;
      FileDisplayer(String filename) {
        super(filename);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(600, 800);
        JTextArea text = new JTextArea();
        try {
          text.setText(Filez.read(filename));
        } catch (FileNotFoundException e) {
          text.setText(e.toString());
        this.add(text);
      public static void main(String args[]) {
        final String filename = (args.length>0 ? args[0] : "C:/Java/home/src/forums/FileDisplayer.java");
        try {
          java.awt.EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                new FileDisplayer(filename).setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
    Filez.read
       * reads the given file into one big string
       * @param String filename - the name of the file to read
       * @return the contents filename
      public static String read(String filename) throws FileNotFoundException {
        return Filez.read(new FileReader(filename));
       * Reads the contents of the given reader into one big string, and closes the reader.
       * @param java.io.Reader reader - a subclass of Reader to read from.
       * @return the whole contents of the given reader.
      public static String read(Reader in) {
        try {
          StringBuffer out = new StringBuffer();
          try {
            char[] bfr = new char[BFRSIZE];
            int n = 0;
            while( (n=in.read(bfr,0,BFRSIZE)) > 0 ) {
              out.append(bfr,0,n);
          } finally {
            if(in!=null)in.close();
          return out.toString();
        } catch (IOException e) {
          throw new RuntimeIOException(e.getMessage(), e);
      }Edited by: corlettk on Dec 16, 2007 1:01 PM - dang [code [/tags][                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • EJB 3.1 @Asynchronous and calling other methods from within

    Hey all,
    I am helping a friend set up a test framework, and I've turned him on to using JEE6 for the task. I am decently familiar with entity beans, session beans, and such. One of the new features is @Asynchronous, allowing a method to be ran on a separate thread. The test framework generally needs to spawn potentially 1000's of threads to simulate multiple users at once. Originally I was doing this using the Executor classes, but I've since learned that for some reason, spawning your own threads within a JEE container is "not allowed" or bad to do. I honestly don't quite know why this is.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
    None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
    My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
    Thanks.

    851827 wrote:
    Hey all,.. from what I've read the main concern is that the container maintains threads and your own threads could mess up the container somehow. I can only guess that this might be possible if your threads use the container services in some way.. but if anyone could enlighten me on the details as to why this is bad, that would be great.
    Yes since the EE spec delegated thread management to conatiners, the container might assume that some info is available in the thread context that you may not have made available to your threads.
    Also threading is a technical implementation detail and the drive with the EE spec is that you should concentrate on business requirements and let the container do the plumbing part.
    If you were managing your own threads spawned from EJBs, you'd have to be managing your EJBs' lifecycle as well. This would just add to more plumbing code by the developer and typically requires writting platform specific routines which the containers already do anyway.
    >
    None the less, EJB 3.1 adds the async capability and I am now looking to use this. From my servlet I use @EJB to access the session bean, and call an async method. My servlet returns right away as it should. From the async method I do some work and using an entity bean store results, so I don't need to return a Future object. In fact, my ejb then makes an HttpClient call to another servlet to notify it that the result is ready.
    My main question though, is if it's ok to call other methods from the async method that are not declared @Asynchronous. I presume it is ok, as the @Asynchronous just enables the container to spawn a thread to execute that method in. But I can't dig up any limitations on the code within an async method.. whether or not it has restrictions on the container services, is there anything wrong with using HttpClient to make a request from the method.. and making calls to helper methods within the bean that are not async.
    Thanks.If you want to be asynchronous without caring about a return value then just use MDBs.
    The async methods have no restrictions on container services and there is nothing wrong with calling other non async methods. Once the async method is reached those annotations don't matter anyway (unless if you call thhose methods from a new reference of the EJB that you look up) as they only make sense in a client context.
    Why do you need to make the call to the servlet from the EJB? Makes it difficult to know who is the client here. Better use the Future objects and let the initial caller delegate to the other client components as needed.

  • Call Java Method from BPM Process

    Hi,
      I have defined a java class with set of methods , and I want to know if there is any way to call those methods from a BPM process..
    Thanks in Advance,,
    Best Regards,,
    Ola Essa..

    Use the spring component context in soa suite instead of ejb. Look for documentation in soa suite developer guide. Only if you have existing ejbs then use ejb adapters.
    See this http://www.oracle.com/technetwork/middleware/soasuite/learnmore/fivecoolusecasesforspring-1885529.pdf
    Vikram
    Message was edited by: VikramFusionApplied

  • How to Call C++ Method from Java

    I need to call C++ method from Java.
    I have gone through the JNI tuorial , but was not able to pin point things.
    I read that :
    You have to write JNI c functions which then call your C++ member functions.You need to write a JNI function which will call new on your C++ class.
    Now i have java class :
    Java Code JavaClass.java ---->
    class JavaClass{
    public native void nativeMethod();
        static
            System.loadLibrary("NativeCppCode");
         private void callCppMethod()
              //call C++ method
                    JavaClass jvc = new JavaClass();
                    jvc.nativeMethod()
    }Cpp Code:
    NativeCppCode.h---->
    class NativeCppCode
    public:
        getValue();
        setValue();
    private:
       int a;
    JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
                   ,jobject obj);NativeCppCode.C---->
    NativeCppCode::getValue()
       return a;
    NativeCppCode::setValue()
       a = 1;
    JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
                   ,jobject obj)
    NativeCppCode* nativeInstabce = new NativeCppCode();
    NativeCppCode.setValue();
    }Is this the correct way to do it.
    Any suggestion would be a great help to me

    tryit wrote:
    I need to call C++ method from Java.Not possible.
    JNI uses C methods.
    Is this the correct way to do it.Same way you would do it in any C/C++ method (not java)
           MyClass* p = ....
           p->doit();
    Common idiom for the pointer in the above is to pass it back and forth to your java code as a java long. You cast it it and from your class pointer. Provide an explicit java method to free it when done. Besides providing the explicit method also implement a finalizer to free it as well (however that is a fail safe and should not be relied upon.)

  • Call native methods from windows dll

    Hello all,
    I want to call BlockInput method from User32.dll. My source code looks something like this:
    public class User32Dll_1 {
         static {
              try {
                   System.loadLibrary("User32");
              catch (Exception ex)
                   ex.printStackTrace();
         public static void main(String[] args) throws UnsatisfiedLinkError {
              BlockInput (true);
         /** @param b
         * @dll.import("USER32")*/
         private static native boolean BlockInput(boolean bBOOL);
    And the problem is that I get the following exception:
    java.lang.UnsatisfiedLinkError: BlockInput
         at User32Dll_1.BlockInput(Native Method)
         at User32Dll_1.main(User32Dll_1.java:27)
    Exception in thread "main"
    Can someone provide me a solution for this?
    Thank you in advance!

    can't do
    use JACOB
    http://danadler.com/jacob/
    or
    http://www.ezjcom.com/

  • Call VO method from application module

    Hi Experts.
    In my case I have created VO and inside implementation class custom method: filterResultsByGroup()
    code:
    public class VO_Business_AreaImpl extends ViewObjectImpl implements VO_Business_Area {
    public VO_Business_AreaImpl() {
    public void filterResultsByGroup() {
    System.out.println("hello");
    now... I would like to call filterResultsByGroup() method from Application Module Imp class:
    code:
    public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
    public AppModuleImpl() {
    public VO_Business_AreaImpl getVO_Business_Area1() {
    return (VO_Business_AreaImpl)findViewObject("VO_Business_Area1");
    public void RunGroupFilter(){
    ViewObjectImpl bussinesArea;
    bussinesArea = this.getVO_Business_Area1();
    ViewCriteria vc = bussinesArea.getViewCriteria("filterResultsByGroup();");
    bussinesArea.applyViewCriteria(vc);
    bussinesArea.executeQuery();
    but it doesn't work. Anyone knows how to call this method?
    Best Regards.

    you code should be like
    VO_Business_AreaImpl bussinesArea;
    bussinesArea = this.getVO_Business_Area1();
    bussinesArea.filterResultsByGroup();

  • How to call java method from C ?

    Hello,
    I try to call a native method from java which calls java method from the same class. Exception (noSuchMethodError) is thrown. Any ideas?
    Thanx in advance !
    here is the source of the native method :
    JNIEXPORT jint JNICALL Java_TestDll_Proc_1Mul_1Int_1Var_1Var_1Stdcall (JNIEnv * env, jclass jcl, jint jarg1, jint jarg2) {
    int arg1;
    int arg2;
    int arg3;
    jint res;
    char * ch = "test";
    jfieldID fid;
    jmethodID mid;
    int (* procedure) (int *, int * ,int *);
    int mch;
    arg1 = (int )jarg1;
    arg2 = (int )jarg2;
    procedure = GetProcAddress(libraryHandle,"Proc_Mul_Int_Var_Var_Stdcall");
    procedure(&arg1,&arg2,&arg3);
    res = (jint) arg3;
    printf("(*env)->GetMethodID(env, jcl, \"test\", \"()V\");\n");
    mid = (*env)->GetMethodID(env, jcl, "test", "()V");
    printf("(*env)->CallVoidMethod(env, jcl, mid);\n");
    (*env)->CallVoidMethod(env, jcl, mid);
    return res;
    here is the source of the java file:
    public class TestDll {
    static {
    System.loadLibrary("testdllwrap");
    System.out.println("java: Library testdllwrap.dll loaded");
    public TestDll() {
    public native int Proc_Mul_Int_Var_Var_Stdcall(int jarg1, int jarg2);
    public void test() {
    System.out.println("java: test()");
    public static void main(String[] args) {
    TestDll access = new TestDll();
    int a = 5;
    int b = 6;
    int c = 0;
    System.out.println("Calling Proc_Mul_Int_Var_Var_Stdcall");
    c = access.Proc_Mul_Int_Var_Var_Stdcall(a,b);
    System.out.println("Java Result = " + c);

    Something is wrong with the code you posted here.
    Since your native method is not static, it should have the jobject instance as a parameter in the function prototype, not a jclass. Also, you should be calling CallObjectMethod with a jobject, not jclass.
    Check out Jace at http://jace.reyelts.com/jace.
    To call the java method you would do:
    JNIEXPORT jint JNICALL Java_TestDll_Proc_1Mul_1Int_1Var_1Var_1Stdcall
    (JNIEnv * env, jobject jTestDll, jint jarg1, jint jarg2) {
      TestDll testDll( jTestDll );
      testDll.test();
    }God bless,
    -Toby Reyelts

Maybe you are looking for

  • When I open a hotmail email on my iPad, it doesn't show as opened when I go on my mac.

    I am a fairly new owner of an iPad air.  Am stumbling on a few issues, one of which is that when I open a hotmail email on my iPad, when I next go to my mac the same email displays as unopened.  It means I am having to duplicate actions with emails. 

  • EMIGALL -  BCONTACT : Problem in upload

    Hi, I am using EMIGALL to upload BCONTACT. However, I am getting the error that Business Partner does not exist. I have successfully uploaded BPs using PARTNER object and relationships using PART_REL. I alos gave PARTNER as KSM for BCONTACT. But stil

  • IPhoto lost my pictures.  Help!

    I uploaded about 1000 pictures from my SD card onto my MacBook Pro using iPhoto.  When prompted I deleted the photos from the SD card (the usual prompt in iPhoto).  The events are now showing up in iPhoto, but they are empty and the pictures are not

  • Java compiler for the mac

    Can anyone tell me where i can get an compiler for the mac os x?

  • ITunes sharing gone?

    I haven't wanted to do this for a while, but I'm sure I recall that you could share the music in an iTunes library with other computers on a network I have 4 macs (all mac OS X 10.5) on a network, all have iTunes (7.6.2(9) ) with music in them. All h