Parent Child classes

Hi All,
I have a really general question that I have not been able to solve.
Here is my sample code:
class parent {
public List mylist
public parent(){
child c = new child(this, mylist);
class child
private parent p;
private List mylist;
private String currentLine ="";
public child(parent p, List mylist){
this.p=p;
this.mylist = mylist;
BufferedReader in new BufferedReader(new FileReader("test.txt"));
while ((currentLine = in.readLine()) != null){
mylist.add(currentLine);
How do I return mylist in the child class back to the parent class? Or secondly, can I declare a List in the child class and have some way of passing it back to the parent class? I am not very familiar with the parent/child classes. If you can assist, I'd appreciate it. Thanks.

Actually....the main problem that I have is that I am using multi threading. Right now the problem that I have is that I can't write to the same output file with multiple children threads...not sure why.
class parent {
PrintWriter out;
public parent () {
out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
for (int i=0; i<10; i++){
childthread ct = new childthread(this);
public synchronized void Output (String output){
out.write(output);
}//end class parent
class child extends Thread{
parent p;
public child (parent p) {
this.p = p;
public void run(){
String thisLine = "test";
p.Output(thisLine);
}//end class child
How can I get all of my 10 threads to write to the same file. Since my parent thread is the one with the output file, each time the child thread calls the p.Output and passes the String..it should printout test in my output file...but it does not. Is there any reason why?
My output file should display "test" ten times. Please let me know what I am doing wrong...or how I can go about writing multiple threads to the same output file. Thank you.

Similar Messages

  • Parent/child classes vs badi or something else

    Dear Experts,
    I’m looking for some architectural suggestions here on the best way to implement “user exits” with classes.
    Up to now, I have coded my software similar to the SAPMV45A method of having an include with subroutines USEREXIT_BEFORE_HEADER and the like.
    It works okay except that the code doesn’t do a great job of encapsulation.  All data has to be global and that gets to be a pain for cleanup.
    I’m wondering the best way to do this as I am not an expert at all in object oriented development.  I've only implemented BADI on a couple of occasions, found it confusing and were it not for tutorials, I wouldn't have been able to do it at all.
    For example, a common flow of my RFC goes like this:
    Perform userexit_initialize in program (sy-repid) if found.
    Perform initialize.
    Perform read_header
    Perform read_items
    Perform populate_header_output
    Perform populate_item_output
    In each of the FORM routines, I have a userexit at the end to allow custom filters or database reads as necessary.
    For example:
    Form read_header
      Select * from header_tab ….
      PERFORM userexit_read_header_finished in program (sy-repid) if found.
    Endform.
    I had hoped I could have two classes, a parent or “core” class to which I can implement only child methods as needed.
    Therefore, it would be more along the lines of:
    Function z_my_rfc
      Importing i_docnum
      Exporting e_header
                     Et_items
                    Et_bapiret2
    Call zcl_core->read_header
    Call zcl_core->read_items
    Call zcl_core->populate_header
    Call zcl_core->populate_items
    What I haven’t really been able to figure out is if I can create and distribute another class zcl_child which I can then customize at every implementation by simply adding a new method and using “super” to incorporate the logic of the zcl_core class.
    I think I’ve seen that this can be done in local class development ( in an include abap program ) but I want to do this in actual classes via SE24.
    Now, my other thought is that this is what BADI are for??
    Periodically, I want to send my customers a transport with update ZCL_CORE class code/methods, etc. but I want to leave the ZCL_CHILD class alone.
    Hopefully, I’ve conveyed my desire here and perhaps you can suggest the simplest way to support this software going forward.
    Thanks in advance for your time and consideration.

    Hi Ray,
    Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
    Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
    What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners
    The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
    How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
    How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
    Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
    Cheers,
    Mahesh

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

  • Casting parent class to a child class

    Hi,
    I have a static method which returns a class called parent. Now I want to cast it it's child class. There are no compilation errors, but at runtime it's throwing me ClassCastException. This is what I'm doing.
    public Parent getObject() {
    Parent p = new Parent();
    return p;
    Child c = (Child) getObject();What is wrong with this code? I couldn't figure it out.
    Any help will be appreciated.
    Thanks,

    Parent p1 = new Parent(); // 1
    Parent p2 = new Child(); // 2
    Child c1 = new Parent(); // 3
    Child c2 = new Child(); // 4
    Parent p1 = (Parent)c1; // 5
    Parnet p2 = (Parent)c2; // 6
    Child c3 = (Child)p1; // 7
    Child c4 = (Child)p2; // 81: Ok.
    2: Ok. Every Child IS-A parent.
    3: Compile time error. A Parent object is not a Child.
    4: Ok.
    5: Ok, because every Child IS-A parent, and the cast is unnecessary. (Though since 3 is illegal a compile time we wouldn't actually have this situation.)
    6: Ok, and the cast is unnecessary, because every Child IS-A Parent.
    7: ClassCastException at runtime. The object is not a Child.
    8: Ok.

  • Executing a child class from parent.

    Hi, well, I have this parent class which I need to execute a method from a child class to get a significant part of the thing get started. Is there anyway for me to accomplish this or a workabout? Thanks..

    Sure.. I have this method in the class logic:
         public void createLocation() {
              try {
              classCoord coordSet = appinterface.decodeFile();
              int areaNum = coordSet.areaNum, cellNum = coordSet.cellNum, signalStrength = coordSet.signalStrength, receiverId = coordSet.receiverId;
              String dateTime = coordSet.dateTime, userName = coordSet.userName, location = calLocation(areaNum, cellNum);
              boolean validity=calValidity(signalStrength);
              classLocation locationObj = new classLocation(this.type, userName, receiverId, validity, location, dateTime);
              appinterface storeLocationObj = new appinterface();
              storeLocationObj.storeLocation(locationObj);
              catch (IOException ioException) {
                   appinterface.displayMessage("Logic Error: " + ioException);
              catch (ClassNotFoundException classNotFoundException) {
                   appinterface.displayMessage("Logic Error: " + classNotFoundException);
         }I need to execute this method halfway in the class appinterface, the logic class inherits from appinterface cuz I need to make use several methods from it. Is there any way to solve this somehow?

  • How to listen to user actions in child class from parent class?

    Hi,
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:
    textField.addKeyListener( new KeyAdapter()
                @Override
                public void keyPressed( final KeyEvent e )
                    //user typed something
                    userTyped = true;
             });Now I have another parent class that uses ChildCustomForm, and parent class has to know once user types, then set
    its own userTyped flag.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).
    I am wondering if there is a way to do this?
    regards,

    jack_wns wrote:
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:You want to listen for input into the textbox, correct? This may take the form of keyboard input, or could be a paste-text event in which case your keylistener will miss it. I recommend that you look into a DocumentListener here so you will catch any changes, be they keyboard or cut or paste.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).The observer pattern may work here.

  • Seemingly unpredictable results when calling an overriden parent method on an instance of a child class casted to the parent class

    I have a parent class with a sub-vi Override.vi, and a child which overrides this sub-vi.  I create an instance of this child.  I cast this child to it's parent class and store it in an array.  Later, if I invoke the parent's 'Override.vi' on this child (casted to parent) then Labview 2013 seems to randomly choose whether to run the parent or the child override.vi.  In Labview 2011 SP1 it would always call the childs version of override.vi (which while surprising to me was very useful).  This has totally broken an application I have been developing, any insight as to how to control which override.vi is run would be helpful (re-casting to the child class isn't really an option, as there are in fact many child classes each with their own version of override.vi).

    The actual data type of the wire is irrelevant in deciding which VI to run. The only thing that is relevant is the class of the object which is actually on the wire, so casting to the parent should not be relevant. *IF* the object really is a child, then LV should always call the child's VI, just like you say it works in 2011.
    I suspect that what's happening in your case is that somewhere you're generating a parent and that's what's actually on the wire (e.g. maybe you have an error somewhere and a function outputs the default value, which is a parent). The fact that it didn't happen in 2011 doesn't mean it's a bug in 2013. It could be that something else has changed.
    In any case, it's impossible to tell whether this is a misunderstanding, a bug in your code or a bug in LV without actual code. If you can post actual code which shows this, people can help. Otherwise (if it only happens in code you don't want to publish), you should try contacting NI directly so that you can at least show them the code.
    Try to take over the world!

  • Parent class not waiting for child class to finish

    hi,
    i have class a and method x in class a which calls class b. its fine till there. but before my class b's action is completed, in which i have to choose a file and display those files in jtable, the remaining lines in method x getting executed. what do you think the problem is.
    i.e. my parent's class method is completely getting executed before the child class (frame) returns the result and is closed. where do u think the problem.
    please help.

    i dont know if i made myself clear. i am giving my code below.
    class A{
    btnClick{
    pnlProductsImport _pnlProductsImport=new  pnlProductsImport(dataSource,config,parent,importFile);
    _pnlProductsImport.setVisible(true);
    _pnlProductsImport.show();
    getProducts()
    here its showing my pnlProductsImport class screen and before I close that screen, getProducts method is getting executed. as I know, the control passes from class A to pnlProductsImport at show() and when its closed, it will execute remaning lines i.e getProducts, but in this case, it shows the subclass, and immedietly, executing remaining lines. but its also fact that my subclass (pnlProductsImport) implements Runnable, but thread starts only after some time when I click on one of the buttons on the screen.... and i want that getProducts() method to execute only when subclass closes completely.
    thanks

  • Cleaning up child class on parent wire

    I have a child class running on a parent wire. The parent class has a reference, and the child class has some additional references. I want to clean these up during shutdown. But, because it is a parent wire, I cannot call my child class's "destroy" method directly. Is the best way to handle this to have destroy.vi be dynamic dispatch, so it will call the child's destroy method via DD, and set "call parent method" to required? This way if the class is a child, it will dynamic dispatch the child's method, but force the programmer to also call the parent method? How have others handled this?
    CLA, LabVIEW Versions 2010-2013

    for(imstuck) wrote:
    Is the best way to handle this to have destroy.vi be dynamic dispatch...?
    Yes. That's the whole point of DD.
    Note that for cleaning up resources, the order of the cleanup might be important, so either write in such a way that it doesn't matter or document it so that the developer of the child class knows exactly when the parent destroy should be called.
    Try to take over the world!

  • Overriding VO Impl class methods to populate parent-child VO

    Hi All,
    I need to populate parent child VOs by giving webservice calls from respective impl classes.
    Scenario : Lets say suppose i have 2 VOs as DepartmentVO and Employee VO with a viewLink on departmentId. Taking a particular instance, in Department table there are 2 rows and for each parent row we have 2 child rows in Employee.
    Webservice Structure : I have a parent Object and inside that parent object i have list of child objects
    e.g : public class DepartmentDTO{
    private List<EmployeeDTO> employeeList;
    After that i have extended Impl classes for both VOs and overriden method i.e. "executeQueryForCollection" to give a webservice call and get back response of DepartmentDTO[] with List<EmployeeDTO> inside it.
    In DepartmenntVOImpl class i have overriden "createRowFromResultSet" which populates the parent VO with the number of parent records returned from webservice.
    Code for Department impl class is :
    protected ViewRowImpl createRowFromResultSet(Object qc,
    ResultSet resultSet) {
    Iterator deptIter= getPackageClassIterator(qc);
    ViewRowImpl r = createNewRowForCollection(qc);
    DepartmentDTO curDTO = (DepartmentDTO )deptIter.next();
    populateAttributeForRow(r,
    findAttributeDef("DeptId").getIndex(),
    curDTO.geDeptId() );
    populateAttributeForRow(r,
    findAttributeDef("DeptName").getIndex(),
    curDTO.getDeptName() );
    return r;
    Similarly i have overridden "createRowFromResultSet" method in EmployeeVOImpl to populate the child VO(this need to be populated from the list object inside parent object reponse)
    Code as follows :
    protected ViewRowImpl createRowFromResultSet(Object qc,
    ResultSet resultSet) {
    Iterator empItr= getPackageClassIterator(qc);
    ViewRowImpl r = createNewRowForCollection(qc);
    DepartmentDTO curDTO1 = (DepartmentDTO )empItr.next();
    List<EmployeeDTO> list = curDTO1.getEmployeesList();
    for (EmployeeDTO curDTO : list) {
    populateAttributeForRow(r,
    findAttributeDef("EmpId").getIndex(),
    curDTO.getEmpId());
    populateAttributeForRow(r,
    findAttributeDef("EmpName").getIndex(),
    curDTO.getEmpName() );
    populateAttributeForRow(r,
    findAttributeDef("EmpLastName").getIndex(),
    curDTO.getEmpLastName() );
    populateAttributeForRow(r,
    findAttributeDef("DeptId").getIndex(),
    curDTO.getDeptId());
    return r;
    Though the code looks simple and correct but the child records are not getting populated correctly. Am not sure if the code implementation to populate parent child VOs from webservcie is correct or not.
    Would appreciate for Help or valuable Suggestions.
    -Sanjeeb

    Hi Ray,
    Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
    Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
    What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners
    The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
    How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
    How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
    Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
    Cheers,
    Mahesh

  • Inheritance problem with parent class calling child class

    I have a problem with inheritance with a parent class calling a child class method. Below is the example pseudocode code and my problem:
    public abstract class A {
        protected void function1 ( ) { }
        protected void function2 () {
             //calls function1();
             function1();
    public abstract class B extends A {
        protected void function1 ()  {
             // do stuff
    public class C extends B {
        protected void function1 ()  {
            // do stuff
            super.function1 ();
    }I have an object instance of class C created and its function2() is invoked.
    My problem is, while in function2(), which belongs to abstract class A and the method call to function 1() is called, the call invokes the function1() of class B. Shouldn't the call invoke function 1() of class C instead? And then function1() of class B will be called after due to the super.function1(). It's not behaving like I thought it would.
    Edited by: crono77 on Jan 10, 2008 8:13 PM

    Nevermind, i found my error :)

  • Can I make methods which are public in a parent class into private in a child class ?

    I suspect the answer to my question is probably no, but...
    I have a parent class that provides several general purpose methods, I also have a child class which is intended to provide a more specific set of methods for manipulating the data in the class. As a result, calling some of the parent's methods on the child class can provide results that I'd rather not let the users of the child class have to worry about. It seemed (from my rather naive OOP experience) that the nicest way to do this would be to make access to some of the parent's public methods be private in the child class. This doesn't seem to be trivially possible.... ?
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/

    Hi Gavin,
    Unfortuneately I don't think this can be done. You can use an overide VI to change the functionality of a method in a child class but it has to have the same scope and the method it overides.
    Regards
    Jon B
    Applications Engineer
    NI UK & Ireland

  • Parent class private data accessable in Child class?

    Hi!
    I thought that this would be obvious, but my search foo fails me.  Hopefully someone would be kind enough to answer my newbie LVOOP question.
    I have a a parrent class.  This parrent class contains a cluster of class private data.  I setup all the accessor methods to this data.  I create a child class that has functions that need to access data stored in its parrent class.  Its inheritence is set, but when I try to unbundle the class data all I can seem to get to is what is setup in the child class' data cluster.
    I've watched a video and it looked like the data cluster magically appeared and was accessable through the children methods.  What am I missing?
    Thanks for input!
    -nic
    Solved!
    Go to Solution.

    Nickerbocker wrote:
    Well, that makes sense.
    One other quick question.  Is the procedure, New->"VI for Override..." from the context menu of my child class the only way to create a method that overrides the parents method?  Where is the property that defines this newly created VI as overriding my parent's VI?  Can I simply create a VI that is named the same and it have the same effect?
    That is the only method I use but I believe if you get all of your icon patterns and terminal marking as dynamic and all of the other rules, you should be able to do the same thing by hand (I base this guess on the fact I messed with those things and broke my ever-rides).
    The only thing I think has to be done from the project (scripting aside) is to set-up the inheritance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

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

  • Class override, how to create the child class and then the base class

    I started to write a program for a smart DMM, the problem is every version of the DMM the company change the communication commend.
    My idea is to write a child class for every DMM version and every SubVI of the child will override the base class SubVI.
    My problem is, i want first to create one child class and after i will see every thing is work,  start to create the base class. that way i will see if am thinking the right way.
    My question is
    How can i create a child class and then create the base class and configure the SubVi of the child class to be Override of the base class?
    I tried to search in the property of the class but i didn't see nothing.
    Thanks
    Solved!
    Go to Solution.

    This can be done and I've done it on occasion.
    You simply create the base class with the dynamic dispatch methods you require (connector panes need to be identical to thos of the child class).
    Then set the inheritance of the class to inherit from this base class.  If your method is defined as a dynamic dispatch method in the parent, you'll most likely now have some errors (unless your child method was already DD in which case you might just be OK already).
    To change the inheritance of a class, right-click the properties of the class in your project and select properties.  I believe the ineritance tree is at the lower end of the properties.  Click on the "change inheritance" (or something similar) to choose the class from which you now wish to inherit.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

Maybe you are looking for

  • Error in DC project while executing in NWDS

    Hi All, I have certain source codes of already developed webdynpro components. But when I try to execute the same in NWDS,it's showing a lot of errors....starting from import statement. Errors are listed below.... Missing required library: 'C:Users/u

  • HELP! Cannot find Laserwriter in Print Center w/AppleTalk

    I can connect to the Internet through ethernet, but cannot add a printer. When I go to Network prefs, AppleTalk is enabled, although the Zones pulldown is grayed out. I read some posts and already tried fixing permissions, but no luck. I also upgrade

  • ITunes version 6.0 now "the" band listed under letter "t"

    After I downloaded the newest version of iTunes, all bands that have a "The" in their name, are listed under the letter "t" and not under their actual name. This wasn't the case with the previous iTunes versions. I have tons of music on my iPod and i

  • Mail service automator

    hi i setup a service with automator in mail in mountain lion, i upgraded to mavericks and the call of this service within mail application don't work now (the keyboard shorcut still works). it simply doesn't start. i test it in automator and everythi

  • Plugging apple Flat screen in mac mini.

    I have just ordered a mac mini and want to plug and 'older' mac 17 inch flat screen into it, the clear bezel one, i.e. the flat screen which was out just before the current range. It occurs to me this has an ADC connection, would I be right in guessi