Instantiation of similar object over a super class deciding the sub class

Hello all
First, sorry if I'm duplicating an already answered question. I didn't searched very deep.
Initial position:
I have 2 Object (A1 and A2) which share the most (about 90%) of their instance variables an the associated methods. The values of the instance variables are retrieved in the real implementation from a stream. Depending of the data of the stream, I have to instantiate either a A1 or A2 object.
A test implementation (using an int in case of the stream):
The super class A:
package aaa;
public class A
  protected int version = -1;
  protected String name = null;
  protected AE ae = null;
  protected A()
  protected A(int v)
    // Pseudo code
    if (v > 7)
      return;
    if (v % 2 == 1)
      this.version = 1;
    else
      this.version = 2;
  public final int getVersion()
    return this.version;
  public final String getName()
    return this.name;
  public final AE getAE()
    return this.ae;
}The first sub class A1:
package aaa;
public final class A1 extends A
  protected A1(int v)
    this.version = v;
    this.name = "A" + v;
    this.ae = new AE(v);
}The second subclass A2:
package aaa;
import java.util.Date;
public final class A2 extends A
  private long time = -1;
  protected A2(int v)
    this.version = v;
    this.name = "A" + v;
    this.time = new Date().getTime();
    this.ae = new AE(v);
  public final long getTime()
    return this.time;
}Another class AE:
package aaa;
public class AE
  protected int type = -1;
  protected AE(int v)
    // Pseudo code
    if (v % 2 == 1)
      this.type = 0;
    else
      this.type = 3;
  public final int getType()
    return this.type;
}To get a specific object, I use this class:
package aaa;
public final class AFactory
  public AFactory()
  public final Object createA(int p)
    A a = new A(p);
    int v = a.getVersion();
    switch (v)
    case 1:
      return new A1(v);
    case 2:
      return new A2(v);
    default:
      return null;
}And at least, a class using this objects:
import aaa.*;
public final class R
  public static void main(String[] args)
    AFactory f = new AFactory();
    Object o = null;
    for (int i = 0; i < 10; i++)
      System.out.println("===== Current Number is " + i + " =====");
      o = f.createA(i);
      if (o instanceof aaa.A)
        A a = (A) o;
        System.out.println("Class   : " + a.getClass().getName());
        System.out.println("Version : " + a.getVersion());
        System.out.println("Name    : " + a.getName());
        System.out.println("AE-Type : " + a.getAE().getType());
      if (o instanceof aaa.A2)
        A2 a = (A2) o;
        System.out.println("Time    : " + a.getTime());
      System.out.println();
Questions:
What would be a better way to encapsulate the logic into their respective objects ? Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?
Thanks in advance
Andreas

Hello jduprez
First, I would thank you very much for taking the time reviewing my problem.
Just for the record: have you considered regular serialization? If you control the software at both ends of the stream, you could rely on standard serialization mechanism to marshall the objects and unmarshall them automatically.In my case, I can't control the other site of the stream. At the end, the data comes from a FileInputStream and there aren't objects on the other site, only pur binary data.
- It seems you have one such factory class. Then you already have encapsulated the "determine class" logic, you don't need to add such logic in superclass A.I thought from an OO view, that the super class A is responsible of doing that, but that's where the problem starts. So at the end, it's better doing it in the factory class.
- A itself encapsulates the logic to load its own values from the stream.
- A1 and A2 can encapsulate the logic to load their own specific value from a stream (after the superclass' code has loaded the superclass' attributes values).
My advise would be along the lines of:
public class A {
.... // member variables
public void load(InputStream is) {
... // assign values to A's member variables
// from what is read from the stream.
public class A1 extends A {
... // A1-specific member variables
public void load(InputStream is) {
super.load(is);
// now read A1-specific values
public class AFactory {
public A createA(InputStream is) {
A instance;
switch (is.readFirstByte()) {
case A1_ID:
a = new A1();
break;
case A2_ID:
a = new A2();
break;
a.load(is);
}The example above assumes you have control over the layout of the data in the stream (here for a given A instance, the attributes defined in A are read first, then come the subclass-specific attributes.
The outcome is: you don't have to create a new A( ) to later create another instance, of a subclass.I like the idea. In the AFactory, is the "A instance;" read as "A a;" ?
Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?Note I initially read this question as "can an instance of a class mutate into another class", to which the answer is no (an object has one single, immutable class; it is an instance of this class, and of any superclass and superinterface, but won't change its class at runtime).Yes, I have been thinking about a way for mutating into a subclass to keep the already initialized values from the A class without copying or parsing again. But preventing an instance of an A class will be my way. So, in this aspect, Java didn't changed in the last 10 years... It's a long time ago I've used Java for some real projects.
You can, however, create an instance of another class, that copies the values off a priori A instance. Your example code was one way, another way could be to have a "copy constructor":
public class A {
public A(A model) {
this.att1 = model.att1;
this.att2 = model.att2;
public class A1 {
public A1(A model) {
super(model);
... // do whatever A1-specific business
)Still, I prefer my former solution less disturbing: I find the temporary A instance redundant and awkward.Nice to know. I prefer the first solution too.
Thank you again for the help and advices. My mind is searching sometimes for strange solutions, where the real is so close ;-)
Andreas

Similar Messages

  • Why Object is a super class in java?

    hi all i have got one basic doubt in java. why Object class is a super class in java. C++ is also a object oriented language but there there is no concept of making object as a super class, but in java why we are having that. thanks

    Personally, I find the fact that C++ (and Delphi) DOES NOT have a common base class something of an inconvenience at times. The reason is that Java is an (almost) pure Object Oriented language, while C++ and Delphi are partially-object-oriented additions to C and Pascal respectively.
    RObin

  • How call the constructor of the super type in the sub type?

    Hi, everybody:
    There are two type as belowing code:
    CREATE TYEP super_t AS OBJECT (
    a NUMBER(7,1),
    b NUMBER(7,1),
    CONSTRUCTOR FUNCTION super_t
    (a IN NUMBER:=null, b IN NUMBER:=null) RETURN SELF AS RESULT
    ) NOT FINAL;
    CREATE TYEP sub_t UNDER super_t (
    CONSTRUCTOR FUNCTION sub_t RETURN SELF AS RESULT
    Because super_t has the constructor that can pass 0 to two parameters, does the constructor of the sub_t can call the constructor of the super_t to create the instance of the sub_t?
    If can, how call?
    If not, need to rewrite the code as the constructor of the super_t in the constructor of the sub_t?
    Thank you very much!

    No the supertype constructor is not automatically called (that should have been trivial for you to prove to yourself). Unfortunately, you can't call it from the subtype either (there is functionality like Java's 'super'). You could define a named method in the supertype that does the initialization and call that in both the constructors however.

  • How to indicate the object of the super Class ?

    hello,
    I need to notify when one dialog is close to the class that generated it.
    Of course I do it from the method windowClosing() in the class WindowAdapter.
    But if I use "this" how parameter in the method, I noted the value is that of the inner anonymous class, and not that of the dialog class.
    I write down some code to reproduce the problem ....
    public ReferenceToTheSuperClass() {
            final SecondClass sc = new SecondClass(this);
            jButton1 = new javax.swing.JButton();
    //        final ReferenceToTheSuperClass xx = this;
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                     sc.checkSuper(xx);                    // work
                     sc.checkSuper(this);                   // not work
                     sc.checkSuper(super.getClass()); // not work
    }  // ReferenceToTheSuperClass
    class SecondClass {
        ReferenceToTheSuperClass superiorClass;
        public SecondClass(ReferenceToTheSuperClass supClass){
            superiorClass = supClass;
        public void checkSuper(Object o){
            if (o instanceof ReferenceToTheSuperClass){
                JOptionPane.showMessageDialog(null,"HELLO");
    } // SecondClass My ask is: It is possible to indicate the value of the instance of the super Class, inside one his anonynimous inner class?
    thank you
    regards
    tonyMrsangelo

    thank you for your kinkly answer jeverd,
    yes what you say is right, in this case the class is only nested (in the hurry I used a wrong word).
    About the sintax, I vould find only a short statement to use inside the inner anomymous class and, reading what you say, I can guess it is not possible to do it..
    again thank you
    regards
    tonyMrsangelo

  • Invoked super class constructor means create an object of it?

    Hei,
    i have create one class that extends another class. when i am creating an object of sub class it invoked the constructor of the super class. thats okay.
    but my question is :
    constructor is invoked when class is intitiated means when we create an
    object of sub class it automatically create an object of super class. so means every time it create super class object.

    Hi,
       An object has the fields of its own class plus all fields of its parent class, grandparent class, all the way up to the root class Object. It's necessary to initialize all fields, therefore all constructors must be called! The Java compiler automatically inserts the necessary constructor calls in the process of constructor chaining, or you can do it explicitly.
       The Java compiler inserts a call to the parent constructor (super) if you don't have a constructor call as the first statement of you constructor.
    Normally, you won't need to call the constructor for your parent class because it's automatically generated, but there are two cases where this is necessary.
       1. You want to call a parent constructor which has parameters (the automatically generated super constructor call has no parameters).
       2. There is no parameterless parent constructor because only constructors with parameters are defined in the parent class.
       I hope your query is resolved. If not please let me know.
    Thanks & Regards,
    Charan.

  • JBuilder: Failed to Load Super Class java.lang.Object

    Hi I am a beginner of JBuilder. When I tried to compile some samples from JBuilder, the compiling failed because "Failed to Load Super Class java.lang.Object." Any clue to fix the bug?
    Mark

    Hi
    Thanks for you guys' help. I found that when I create a project, the JBuilder's JDK homepath pointed by default to a JDK directory not existed. Therefore, I modified the JDK homepath through Tools/Configure JDKs. Then it worked.

  • Why a sub class reference cannot hold a super class object

    class a
    class b extends a
    public static void main(String args[])
    b o1=new a();
    I know this code wont compile but i need explanation on why subclass reference cannot hold superclass object

    In short, because the subclass reference might be expected to point to an object with methods or members that the superclass object does not have.

  • Super class methods

    How to get the methods of current class and its super class using reflection. The retrieved methods should be only the methods of user-defined classes but not methods of Java APIs such as Object or any other class provided in JDK.
    For ex, If Class B is inheriting Class A, i need the methods which are declared only in A & B but not from the Object Class. Similarly, If class C is extending any JDK API such as Thread, I need only the methods declared in class C.

    thanku very much for the answer.
    I am trying to execute the methods of another class using reflection. So I have to consider the inherited methods also. For that, I have to differentiate between standard classes & user-defined classes.Assume that u have one GUI screen where in once u select a class all its methods including inherited methods have to be displayed.
    I can get the the superclass using the method getSuperClass(). But inorder to get the protected methods of superclass what is the method to be used ? If I use getMethods(), it returns only public methods, where as getDeclaredMethods() returns all the methods. Since I have to execute only public & protected methods, what is the best way to solve this ?

  • Access super class private variables

    class A
    private int i,j;
    A()
    i=j=20;
    public void show()
    System.out.println(i+" "+j);
    class B extends A
    int k;
    B()
    super();
    k=20;
    public static void main(String args[])
    B b=new B();
    b.show();
    In the above program, when a instance of class A is created, the memory is allocated for 2 private integer variables(i and j in this case) 8 byte of memory gets allocated and the referance is returned to the object.
    ex:
    A a=new A();
    a contains the address of memory allocated for 2 integer variables.
    In this code there is another class called B which contains only one variable of it's own.when a object is creted for class B only 4 byte of memory is allocated and the reference is returned.
    ex:
    B b=new B();
    b contains address of 4 byte of memory allocated.
    my doubt is when the B's constructor is called,it inturn calls super(),
    where the variables are intialized. variable (i,j) does not exist in memory and how are they getting initialized.are they created at runtime and getting initialized.Though B has no explicit control over these variables it can able to access their values.How is that possible??

    Can you please stop creating multiple threads with the same question. There is already a discussion in your other thread. Please don't waste our time.
    http://forum.java.sun.com/thread.jspa?messageID=4063146#4063146
    Kaj

  • Cfobject - An exception occurred when instantiating a COM object

    I'm getting the following error:
    An exception occurred when instantiating a COM object.
    The cause of this exception was that: java.lang.RuntimeException: Can not use native code: Initialisation failed.
    1 :
    2 : <cfscript>
    3 :     oLoader = CreateObject("com", "easyPDF.Loader.6");
    4 : </cfscript>
    This is on a dedicated server with 64bit Windows Server 8 and 64bit ColdFusion 9.  easyPDF is a program that will convert files into PDF on the server, it is also the 64 bit version.
    I'm not even trying to do anything but load the object and am getting the error.  I took a peek inside the registry and searched for "easyPDF.Loader" and it was found.
    Any ideas what could be going wrong? Is there something I need to do with the CF setup or IIS to get this working?  It gives the same error with the following line of code as well.
    <cftry>
        <cfobject type="com" action="connect" class="Word.application" name="this.wordCom" context="local">
        <cfcatch>
            <cfobject type="com" action="create" class="Word.application" name="this.wordCom" context="local">
        </cfcatch>
    </cftry>
    Any help or guidance would be great.  Is there a basic <cfobject type="com"> that should work on ANY computer without installing something that I could use to test?
    Thanks!

    Just to give everyone some closure in this matter:
    I've opened a case with Adobe Support. Their reply was:
    COM interoperability with CF9 is not supported on 64 bit Windows OS. This is due to the limitations imposed by JIntergra. You can find a reference for this in the following tech-note:http://helpx.adobe.com/coldfusion/kb/coldfusion-limitations-running-coldfusion-64.html
    It seems that J-Integra (http://j-integra.intrinsyc.com/support/kb/article.aspx?id=30963) won't update their code libraries for 64-bit support due to lack of customer demand for this functionality. Mind you this is the newest technot I could find on the matter but it was last update in 2010. I've also emailed j-Integra sales (http://j-integra.intrinsyc.com/contact.asp) to inquire about any progress in porting over their libraries to 64-bit. Who knows, if they get enough requests...
    I will now try to access my COM libraries from a .NET dll and call it using cfexecute.

  • Why isn't there a simpler way to initialize a subclass with its super class

    Let me explain my doubt with an example...
    public class Parent {
    �    public String parent;
    public class Child extends Parent{
    �    public String child;
    I've an instance of Parent p. I want to construct Child c, with the data in p.
    The only way that is provided by Java language seems to be, having a constructor in Child like
    public class Child extends Parent{
    �    public String child;
    �    public Child(Parent p){
    �    �    parent = p.parent;
    �    }
    The problem with this is there is lot of redundant assignment code.
    What I don't understand is why there is not a simpler way of doing this when a subclass is after all super class data + some other data(excuse me for not looking at the bahavior part of it)
    I'm looking for something as simple as Child c = p, which I know is wrong and know the reasons too.
    Yes, we can wrap Child over Parent to do this, but it necessitates repeating all the methods in Parent.
    Why is the language writers didn't provide a simple way of doing this? I should be missing something here...I'm just searching for an explanation. May be I'm asking a dumb question, but this bugs me a lot...
    Regards,
    Kothapalli.

    To answer DrClap, I'm demanding it now :-). Let me
    not suggest something that Mr.Gosling didn't think of;
    he should be having some reasons in not providing it.Because it's essentially impossible in the general case. One of the reasons you may be extending a class is to add new invariants to the superclass.
    eg- extend java.awt.Rectangle by BoundedRectangle - extra invariant that none of its corner points may be less than 0 or more than 100 in any dimension. (The rectangle must be entirely contained in the area (0,0)-(100,100))
    What would happen if you try to create a BoundedRectangle from a rectangle representing (50,50)-(150,150)? Complete invariant breakdown, with no generic way to handle it, or even recognise it.
    Actually, BIJ and sgabie are asking for it. Provide an
    automatic copy constructor. Every object should have
    an implicit copy constructor defined. From any
    subclass, I should be able to invoke
    super(parentClass). From the subclass, we can invoke
    super(parentClass) first and then go on to initialize the
    subclass data.
    I really don't know the implementation issues of this,
    but what I'm looking for is something like this. I'm just
    curious to know the implementation issues.Implementation issue #1: Classes that should not, under any circumstane, be copied.
    * eg 1- Singleton objects. If there's an automatic copy constructor, then multiple singletons can be created, making them essentially useless. This by extension kills the Typesafe Enum pattern also.
    * eg 2- Objects with extra information, such as java.sql.Connection - if you copied this, would the copy be using the same socket connection, or would another connection be required? What happens if opening another connection, and the JDBC driver requires the password to be entered for every new connection? If the wrong password is entered, what happens to the newly creating connection?
    Implementation issue #2: Copying implementation?
    * Already mentioned by RPWithey. The only guaranteed way to perform the copy would be with a shallow copy, which may end up breaking things.
    Why can't you write the copy constructor yourself? If it's a special case, it only has to be done once. If it's a recurring case, you could write a code generation tool to write them for you, along with most of the rest of the class.

  • Error while calling a super class public method in the subclass constructor

    Hi ,
    I have code like this:
    CLASS gacl_applog DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
                create_new_a
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXPORTING  pfx_log_hndl TYPE balloghndl
                   EXCEPTIONS error
    ENDCLASS.
    CLASS gacl_applog IMPLEMENTATION.
      METHOD create_new_a.
        DATA: ls_log TYPE bal_s_log.
      Header aufsetzen
        MOVE pf_extnumber TO ls_log-extnumber.
        ls_log-object     = pf_obj.
        ls_log-subobject  = pf_subobj.
        ls_log-aluser     = sy-uname.
        ls_log-alprog     = sy-repid.
        ls_log-aldate     = sy-datum.
        ls_log-altime     = sy-uzeit.
        ls_log-aldate_del = ls_log-aldate + 1.
        CALL FUNCTION 'BAL_LOG_CREATE'
             EXPORTING
                  i_s_log      = ls_log
             IMPORTING
                  e_log_handle = pfx_log_hndl
             EXCEPTIONS
                  OTHERS       = 1.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID      sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
      PUBLIC SECTION.
        DATA: log_hndl   TYPE balloghndl READ-ONLY
            , t_log_hndl TYPE bal_t_logh READ-ONLY
        METHODS: constructor
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXCEPTIONS error
               , msg_add      REDEFINITION
               , display      REDEFINITION
    ENDCLASS.
    CLASS gcl_applog_temp IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD create_new_a
               EXPORTING  pf_obj       = pf_obj
                          pf_subobj    = pf_subobj
                          pf_extnumber = pf_extnumber
               IMPORTING  pfx_log_hndl = log_hndl.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
    ' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'
    Can you please suggest how to change the code with out affecting the functioanlity.
    Thank you ,
    Lakshmi.

    Hi,
    Call that method by instance of Subclass.   OR
    SUPER-->method.
    Read very useful document
    Constructors
    Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
    The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
    METHODS CONSTRUCTOR
            IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
            EXCEPTIONS.. <ei>.
    and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
    The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
    CLASS-METHODS CLASS_CONSTRUCTOR.
    and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
    Pls. reward if useful....

  • 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?).

  • Overwriting a method of a super class in the subclass ???

    Hi,
    can somebody tell me whether it's possible to add a new implementation of a method in the sub class which is inherited from a super class?
    I want to model my program in that way:
    1. I define a super class with some implemented methods.
    2. This class should be inherited in a sub class. One method should be used as it was implemented in the super class but another method should be overwritten in the subclass.
    I know this concept from Java but I couldn't find a way how to do it in ABAP
    Many thanks for any help!
    Best regards,
    Birgit

    hi,
    yeas you can do it,
    Subclass can re-implement  the inherited public and protected methods from superclass.Class C1 contains method METH1(public) and METH2(protected), both of which are modified and re-implemented in  its subclass C2.also you can have ur own methods in subclass.Objects are created out of both classes and the method METH1 for both objects are called.
    Output of the program demonstrates different behaviour for method METH1 of class C1 and C2.
    This demonstrates the theme.
    REPORT YSUBDEL.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
       METHODS : METH1.
      PROTECTED SECTION.
       METHODS METH2.
      ENDCLASS.
    CLASS C1 IMPLEMENTATION .
      METHOD : METH1.
       WRITE:/5 'I am meth1 in class C1'.
       CALL METHOD METH2.
      ENDMETHOD.
      METHOD : METH2.
       WRITE:/5 ' I am meth2 in class C1 '.
      ENDMETHOD.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM C1.
    PUBLIC SECTION.
      METHODS : METH1 redefinition,
      meth3.
    PROTECTED SECTION.
      METHODS : METH2 redefinition.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD METH1.
       WRITE:/5 'I am meth1 in class C2'.
       call method meth2.
    endmethod.
      METHOD : METH2.
      WRITE:/5 ' I am meth2 in class C2 '.
    ENDMETHOD.
    METHOD : METH3.
      WRITE:/5 ' I am own method of class C2'.
    ENDMETHOD.
    endclass.
    START-OF-SELECTION.
      DATA : OREF1 TYPE REF TO C1 ,
             OREF2 TYPE REF TO C2.
      CREATE OBJECT :  OREF1 , OREF2.
      CALL METHOD : OREF1->METH1 ,
                    OREF2->METH1.
    hope it helps,
    regards

  • Calling a particular Method of all subclass from a super class

    hi
    I have a class 'A' which is a super class for 'B' ,'C' , 'D'
    my main method is in the class Main and while on the run i am calling methods of B,C,D form this main class.
    but as the first step of execution i need to call a init method which has been defined in all the sub-classes. and there can be any no of sub-classes and all will have the init method and i have to call the init method for all classes. is this possible to do that in runtime. ie i wil not be knowing the names of sub-classes.
    thanks
    zeta

    Sorry if i had mislead you all.
    I am not instantiating from my super class.
    as mjparme i wanted one controller class to do the
    init method calls
    so i got it working from the link you gave.
    URL url = Launcher.class.getResource(name);
    File directory = new File(url.getFile());
    This way i can get all the classes in that
    in that package
    and from reflection i can get whether it is
    her it is a sub class of the particular super class
    and i can call the init methods by making the init
    methods static
    thanks for the help
    zetaThis is a rather fragile solution.
    If the problem is one of knowing which subclasses exist, I would suggest specifying them explicitly via configuration (system property or properties file or whatever).
    One thing that's not entirely clear to me: Is the init going to be called once for each subclass, or once for each instance of each subclass? It sounds to me like it's once per class, but I want to make sure.

Maybe you are looking for

  • Cost error message at the point of saving a Process Order

    Dear Experts, Raw Materials R458 and R467 are processed to produce semifinished material S229 While creating a Process Order for material S229, at the point of saving the process order I get the following error messages: 1 No cost element segment exi

  • Approval procedure required for Delivery note based on condtions

    Dear All, I have the followings situation in which the business flow is as such that Sales Quotation is made and based on the Sales Quotation AR Down Payment request is made. Once the downpayment is recieved from the customer entries are made in Inco

  • Help with subpicture highlights on looping motion menus

    I created a motion menu in After Effects.  The menu is 11 seconds long.  I set a loop point at 5;18.  When I preview in Encore, the loop is great and everything looks fine.  However, when I burn the disc and play it in a computer, DVD player or PS3,

  • Error 200294 in Daqmxstart task

    Hi,    I am trying to write and read data at the same time form a cdaq chassis 9172. I have 5 NI A/D cards and 2 NI D/A cards. I manage to code it in a way I can generate and acquire from the same chassis. Though I read data fine but when I am trying

  • How many voice messages can be stored on Skype?

    Hi, 1. I wonder how many voice messages can be kept on Skype account? 2. How long can be one voice message? Thanks