Accessing subclass data when parent class is part of private data of another class.

I am working up an OOP test program and have a problem with data access.
I have the following classes defined:
General Test
General Report
Specialized Test
Specialized Report
The Specialized Test and Specialized Report are subclasses of General Test and General Report, respectively.
The General Test class contains a General Report class instance as part of it's private data.
Specialized Test writes a Specialized Report to its parent class data on initialization. The Specialized Report contains additional data items in its private data.
I have a method for Specialized Test where I first access the Report object stored in the General Test private data, then try to access the private data of the Specialized Report, that should be returned.I get a class mismatch, as the General Test accessor does not know it is returning a Specialized Report.
Should I simply typecast the returned report to the more specific class before trying to access the subclass data as shown below, even though it will already be the more specific class?
Thanks,
Josh

I don't see your image - maybe it just hasn't finished uploading yet - but if I'm understanding correctly, using To More Specific Class (not Type Cast) is a fine solution here. It's reasonable to use To More Specific Class to get the wire type to match the type of data that you know it will carry when the compiler cannot make that determination for you automatically.

Similar Messages

  • Accessing variables in a parent class?

    Hello everyone,
    I'm rather new to java, and I've been looking at the documentation a bit but am still trying to figure out just what I am looking for. I've posted an example of such before where I have two seperate files, the parent class file and the child class file. What I want to do is somehow return the instance of parent that child was created with from the below code.
    public class parent {
         protected int var;
         public static void main(String[] args) {          
              child chld = new child();
    }Is it possible to get the same instance of parent that created the child? If so, can it be used to access or modify the variables held by parent? Or is it only possible to do this by creating methods to set or get the value of the variable?
    Can someone point me to the proper term as well, so as I might check the manual as well?

    Another thing I just noticed; your question does not seem to match your post's subject title. Taking that into context, it is possible to read your post very differently. Do you mean that you want to reference parent from inside of its own method, not necessarily after it has returned?
    You can access an object's variables and its methods from within a method it owns. To clarify what I mean...
    public class Something
        int someData = 0;
        public void someAction()
            // Something has a variable "someData" which can be accessed directly from inside of Something's own method someAction()
            someData = 5;
            System.out.println(someData);
    }If you mean you want a reference to the object itself from within one of its methods, Google for the "this" keyword.
    None of these have anything to do with the child object though, so I'm still a bit stumped as to what exactly you mean. Perhaps a combination of all answers received so far?
    Again, you probably need to further clarify exactly what you're looking for.

  • Problems accessing child swf from parent class

    First off: Hi. I'm new - to the forum and to Flash.
    I'm currently writing a flash app that requests a XML feed
    from a Java controller and loads child swfs into various parts of
    the stage based on the settings/URL details received from the XML
    feed.
    Its nearly there and I've got my head round a couple of weird
    things, but theres one thing left that I've found impossible to
    solve. Once the loader class has loaded the swf, it can't access
    its methods or set its variables and the child can't access the
    parent either (or access the parent's variables full stop). From
    what I've read this should be possible. Heres some of my code plus
    pseudo code:
    Note the Panel class is not linked to a symbol and uses
    composition to act like a movie clip, rather than inheritance.
    quote:
    class Panel{
    function Panel(owner:MovieClip, insName:String,
    depth:Number){
    initiates properties etc....
    panelMovie = owner.createEmptyMovieClip(insName,depth);
    listener.onLoadComplete = mx.utils.Delegate.create(this,
    scheduleModule);
    loader.addListener(listener);
    loader.loadClip(moduleX.url, panelMovie);
    function scheduleModule(){
    trace(panelMovie.key);
    trace(panelMove.keyTest());
    panelMovie.key = "dave";
    trace(panelMovie.key);
    Child swf:
    quote:
    var key:String = "test";
    As you can see I create an empty movieclip which I store a
    reference to in this class under the field "panelMovie". I then use
    this (instead of target_mc like you might do with an event handler)
    to try to access the child swf. The output is:
    trace(panelMovie.key); = "test" (Works fine)
    trace(panelMove.keyTest()); = (Nothing returned)
    panelMovie.key = "dave";
    trace(panelMovie.key); = "test" (Previous line = no effect)
    Is this something related to using a class? Really would be
    preferentially to keep all code outside of the fla.
    I've also tried a lot of different combinations of _root,
    _parent and _levelx. None of which I truly understand.
    Any help would be much appreciated! Plus any good tutorial
    links on timeline and referring to objects in it!
    (Couldn't find the code tag/button...)

    >>trace(panelMove.keyTest()); = (Nothing returned)
    You have panelMove here instead of panelMovie
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Accessing XML data from a different class

    Hi all,
    I have an xml class that loads xml data, I need to access the data from another class. I have imported the xml classinto the new class and created a new instance of it. However when I try to access the xml data it is coming back as null. I understand this is almost certainly because when it is called the xml data hasn't completed it's load. How can I get round this?
    xml class:
    package {
        import flash.xml.*;
        import flash.events.*;
        import flash.net.*
        import flash.display.*
        public class xml extends MovieClip
            public var xmlRequest:URLRequest;
            public var xmlLoader:URLLoader;
            public var xmlImages:XML;
            public function xml()
                xmlRequest = new URLRequest("images.xml");
                xmlLoader = new URLLoader(xmlRequest)
                xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
                xmlLoader.load(xmlRequest);
            private function xmlLoaded(event:Event):void
                trace(xmlLoader.data);
                xmlImages = new XML(xmlLoader.data);
    Thanks in advance

    One of the ways:
    package {
         import flash.xml.*;
        import flash.events.*;
        import flash.net.*
        import flash.display.*
        public class XMLLoader extends EventDispatcher
              public var xmlRequest:URLRequest;
              public var xmlLoader:URLLoader;
              public var xmlImages:XML;
              public function XMLLoader()
              public function loadXML(url:String):void {
                   xmlLoader = new URLLoader()
                   xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
                   xmlLoader.load(new URLRequest(url));
              private function xmlLoaded(event:Event):void
                   trace(xmlLoader.data);
                   xmlImages = new XML(xmlLoader.data);
                   dispatchEvent(event);
    Usage:
    var xmlLoader:XMLLoader = new XMLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
    xmlLoader.loadXML("images.xml"):
    function onXMLLoad(e:Event):void{
         trace(xmlLoader.xmlImages);

  • How to use multithreading to access sensor data?

    I'm trying to access sensor data on another thread but keep getting error - No overload for 'OnSensorChanged' matches delegate 'System.Threading.ThreadStart' What am I doing wrong?
            public string str
    { get; set; }
            public void OnSensorChanged(SensorEvent e)
                if (e != null)
                     str
    = e.Values [2].ToString("0.0");
            public void button_OnClick (object sender, EventArgs eventArgs)
                Setup setup = new Setup();
                Thread newThread = new Thread(new ThreadStart(setup.OnSensorChanged));
                newThread.Start();
                newThread.Join();
                newThread.Abort();
                       _text.Text = str;

    Hi Kringle,
    >>No overload for 'OnSensorChanged' matches delegate 'System.Threading.ThreadStart'
    This exception indictates that the method signature for OnSensorChanged does not match the signature defined by a ThreadStart delegate. You need to pass a SensorEvent object into this method, for example:
    Thread newThread = new Thread(setup.OnSensorChanged);
    newThread.Start(new SensorEvent());
    Reference:
    https://msdn.microsoft.com/en-us/library/system.threading.parameterizedthreadstart%28v=vs.110%29.aspx
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • LabVIEW crashes when modifying OOP parent class private data control or typedef contained in that control

    I've been seeing strange behaviour when I modify the private data control of a class, especially if it is a parent class.  It seems that those changes are not always propagated to all the VI's in the project.  This sometimes causes my project to crash with an exception error, or sometimes the problem is more subtle as it will simply write data to the wrong elements in the control (when bundling/unbundling).
    I solve the problem by opening the typedef or class control by itself (i.e. not as part of the project), and then saving it.
    The next time I open the project all problems are solved.  This is a difficult error to track down but I now know to keep a list of typedefs or class controls that I have modified (using subversion helps here), and then when this strange behaviour or crashes happen, I simply close the project and open each modified typedef or class outside of the project and save them individiually.
    Anyone seen something like this too?

    Hmmm.... Have not seen what you are describing -- though occasionally I will see a class that appears broken until I open it by itself outside the project.
    How large is your application?
    How many classes do you use?
    How extensively do you use classes in the application?
    Could you post a screen shot of your project and how things are arranged in it?
    Does the problem seem to be related to any particular class or group of classes?
    Have you tried mass-compiling your code?
    Are the VIs set to separate the object code from the source?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • "Exception Processing Message" error when clicking the Accessing Server Data link on the start page

    When I first started the application, I click the Accessing Server Data link on the start page.  I immediately got the error "Exception Processing Message c0000013 Parameters 75b6bf7c 4 75b6bf7c 75b6bf7c in a dialog box titled "Windows - No Disk".  I had to used Task Manager to remove the box after closing Flash Builder 4.  I then tried the video tutorial on "PHP Services in Flash Builder 4".  I keep receiving an error during service introspection trying to connect to the PHP class.  It was the same error as the other individual "Cannot Connect to PHP Service".  So I tried another tutorial and generated a sample PHP class.  I moved a datagrid on to the stage, droped in the getAllItems function, and configured the return type.  However, when I ran the app, I received the same error "Exception Processing Message" again.  I have attached the screenshot of the error in addition to my phpinfo and log files.

    "The exception process message" is definitely a issue. Is it happening consistently, if so can you file a bug at bugs.adobe.com/flex and give out your machine config details, and the error log.
    With regards to generating a new php file and the introspection error that you are getting, looking at the logs it probably is two fold.
    First off the name of the file and the class name should be the same, are you having employeeServices as the name of the class in employeeServices.php file.
    Second, It seems prior to generating this new file, you had a syntax error at line 5.
    It would be easier to figure out what the error is, if you can also attach the php file, by removing any sensitive information in that.
    Hope this helps.
    Thanks
    -Sunil

  • Reflection: how to get the name of a subclass from parent class?

    Suppose I have a parent class P and two subclasses S1, and S2. There's another method which has an argument of type P. Inside this method, I want to inspect the object (of type P) passed in and print its name, such as "S1" or "S2". How do you do that? I tried Class.getSimpleName(), but "P" is returned no matter which subclass objects you have. Thanks:)

    That's the same as you said last time, and I'm telling you that's not what happens when I test it:
    public class Parent {
    public class SubclassOne extends Parent {
    public class SubclassTwo extends Parent {
    public class TestGetName {
      public static void main(String[] argv) {
        showNames(new SubclassOne());
        showNames(new SubclassTwo());
        showNames(new Parent());
      private static void showNames(Parent p) {
        System.out.println("Name: " + p.getClass().getName());
        System.out.println("Simple name: " + p.getClass().getSimpleName());
        System.out.println("Canonical name: " + p.getClass().getCanonicalName());
    }prints:
    Name: SubclassOne
    Simple name: SubclassOne
    Canonical name: SubclassOne
    Name: SubclassTwo
    Simple name: SubclassTwo
    Canonical name: SubclassTwo
    Name: Parent
    Simple name: Parent
    Canonical name: ParentYou must be doing something else that you're not saying. Either that or you're expressing yourself very poorly. Why not post a simple, self-contained, compilable example of what you claim is happening?

  • How to access the parent class variable or object in java

    Hi Gurus,
    I encounter an issue when try to refer to parent class variable or object instance in java.
    The issue is when the child class reside in different location from the parent class as shown below.
    - ClassA and ClassB are reside in xxx.oracle.apps.inv.mo.server;
    - Derived is reside in xxx.oracle.apps.inv.mo.server.test;
    Let say ClassA and ClassB are the base / seeded class and can not be modified. How can i refer to the variable or object instance of ClassA and ClassB inside Derived class.
    package xxx.oracle.apps.inv.mo.server;
    public class ClassA {
        public int i=10;
    package xxx.oracle.apps.inv.mo.server;
    public class ClassB extends ClassA{
        int i=20;   
    package xxx.oracle.apps.inv.mo.server.test;
    import xxx.oracle.apps.inv.mo.server.ClassA;
    import xxx.oracle.apps.inv.mo.server.ClassB;
    public class Derived extends ClassB {
        int i=30;
        public Derived() {
           System.out.println(this.i);                  // this will print 30
           System.out.println(((ClassB)this).i);  // error, but this will print 20 if Derived class located in the same location as ClassB
           System.out.println(((ClassA)this).i);  // error, but this will print 20 if Derived class located in the same location as ClassA
        public static void main(String[] args) { 
            Derived d = new Derived(); 
    Many thanks in advance,
    Fendy

    Hi ,
    You cannot  access the controller attribute instead create an instance of the controller class and access the attribute in the set method
    OR create a static method X in the controller class and store the value in that method. and you can access the attribute by 
    Call method class=>X
    OR if the attribute is static you can access by classname=>attribute.
    Regards,
    Gangadhar.S
    Edited by: gangadhar rao on Mar 10, 2011 6:56 AM

  • How do I access the data saved on my time capsule?  for example, if i try to view my photos it tells me that i have 2.4gb of photos and gives me the option to "view with iPhoto"....but when i click on "view with iPhoto" nothing happens...  thanks!

    how do i access the data stored on my time capsule?  for example, if i try to view a photo, i get the option to "view with iphoto" but when i click on "view with iphoto" nothing happens.  i'm having similar trouble openning up movies, music, etc.  it appears as though the files exist / saved on the time capsule (because i can see how much storage they consume), but i can't open them.  thanks!

    Unfortunately, Apple removed the feature to "browse backups" in Time Machine backups of iPhoto a few years ago.
    You have to restore the entire iPhoto library to a separate location to be able to "see" it, and then choose the specific images that you want use.
    For complete details, see #15 in Pondini's excellent support document Time Machine -- FAQ.  Check the information in the pink box there.
    Frequently Asked Questions

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

  • Access parent class?

    I'm just wondering if there's some way to access the class that instantiates a class from the instantiated class. Say if I had a class that has a Vector and creates a bunch of other classes that are added to the Vector. Is it possible for the instances of the class to access the Vector? I realize that this is poor OO, but I was just wondering if Java has some way of making this work, or if this just has "rethink idea" all over it... Thanks for your time.

    You can pass a reference variable pointing at the parent to the child object and store it there. Via this pointer you can reach the parent. It's common practice. This for example will print "parent". The parent just let go of the child but the child holds a reference to its parent,
    class Child {
       Parent parent;
       public Child (Parent p) {
          parent = p;
          parent.print();
    class Parent {
       public Parent () {
           new Child(this);
       public void print() {
          System.out.println("Parent");
    Parent p = new Parent();

  • Access global data of report in global class methods?

    Hi all,
    I have defined one global class in SE24 and i am using methods of this class in report program.
    Can i access global data of my report program in class methods directly without declaring it as IMPORT
    parameter?
    Thanks,
    Apita

    Hi,
    Well, now you did confuse me: first you asked about using global data of a report program in global class (created in SE24), and the answer is: no, you can't directly access the global data of another program in a method of global class (yes, you should pass them via importing parameters), and you shouldn't even consider using indirect means of doing so via special form of ASSIGN statement reserved for internal use by SAP. The ASSIGN will not work if someone reuses the global class elsewhere in the system without loading your report. Don't ever program such atrocious dependencies in global class...
    And now you ask about the use "in method implementation in report program"..? Just to be sure - you can't program the implementation of a global class method in a report program.
    You can program a local class inheriting from a global class and redefine/re-implement methods of such global super-class in a report program. Global data of report program, including the selection screen, would be directly accessible to such local class. It would still not be a good idea to use this access:
    Conversely, within an encapsulated unit, that is, within a class, you should avoid accessing more global data directly. Within methods, you should generally modify attributes of the class only. Write access to global data outside the class is not recommended. Accessing data in this way should only be done using specially marked methods, if at all. The use of methods of a class should not evoke any side effects outside the class itself.
    cheers
    Jānis
    Message was edited by: Jānis B

  • I am running Mac OS 10.6.7 I cannot run a java based program from the net when parental controls are set the error is The error is Load: class installer.CheckVersion 13. class not found  Help!

    I am running Mac OS 10.6.7 I cannot run a java based program from the net when parental controls are set the error is The error is Load: class installer.CheckVersion 13. class not found 

    Then, talk to the person running the lab.

  • When i first pluggd my usb from Iphone4s into pc it asked if cud trust my pc, I said yes, it allowd me to access pics/data. Just now i rtnd to pc and i pressd dont trust by accident on my phone. my iphone isnt opening its files on my pc. help wot do i do?

    Help please.
    when i first pluggd my usb from Iphone4s into my pc it asked if I cud trust my pc, I said yes, it then allowd me to access pics/data as I was working on a document and uploading pics into it.
    Just now i rtnd to pc to continue and when asked by my phone if I cud trust my pc i pressd dont trust by accident. my iphone now isnt opening its files on my pc and even tho i remove the usb cable and reinsert it the phone isnt asking me whether I trust the pc at all. help wot do i need to do now?
    Thanks

    Thanks Rob.
    I actually had no clue what the core problem was caused by. So it's Windows itself...that helps some.
    I'll resubmit there. It might actually have saved time for it to simply have been moved to there instead of off-topic, though I suppose you have to follow protocol.

Maybe you are looking for

  • "Place video from URL" not working in InDesign CC 9.1

    Has anyone come across why an H.264 encoded mp4 file won't embed into InDesign CC, but will in CS6? Last week I upgraded from Indesign 9.0 (where it was working) to Indesign 9.1 (where it no longer works). Specifically, I'm using the "Place video fro

  • Flash Builder 4 Enterprise Deployment/Silent Install

    I am attempting to put together a package for Flash Builder 4, to be deployed to developers via SCCM.  Is there a guide on silent deployment with the Volume Licensed FB4 installer? I've not been able to find any documentation on doing this, and the m

  • Big Problem Mail, iPhoto, iMovie

    Hi all!! I have a problem on my iMac OS X 10.7.3 Lion. And there's iPhoto and iMovie and Mail that no longer starts and displays the following message <Mail Left of Mamère imprévu> And every time I make: Crashed Thread: 0 Dispatch queue: com.apple.ma

  • Why has my screen stopped rotating

    My screen has suddenly stopped rotating. Top right of screen shows a lock in circle

  • Weblogic.application.ApplicationException cannot be resolved error

    Hi, I am new to Weblogic Server. I am creating a web application in which I have created a custom MBean. Right now, I am coding the class which extends 'ApplicationLifecycleListener' in order to register the custom MBean automatically when the app is