aspose file tools*
The moose likes Beginning Java and the fly likes sub class access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sub class access" Watch "sub class access" New topic
Author

sub class access

Ashok Paulraj
Ranch Hand

Joined: Jul 07, 2003
Posts: 78
How do I access the subclasses' (B,C and D - subclasses of A) methods from an external class 'Temp' ?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Could you be more specific about these methods? What level of access do they have?
Ashok Paulraj
Ranch Hand

Joined: Jul 07, 2003
Posts: 78
hi,

public class B extends A {

public void setObj (List l) {}
public void instantiateTemp ()
{
Temp t = new Temp ();
t.setParent (this);
}
}

public class C extends A {

public void setObj (List l) {}
public void instantiateTemp ()
{
Temp t = new Temp ();
t.setParent (this);
}
}

public class D extends A {

public void setObj (List l) {}
public void instantiateTemp ()
{
Temp t = new Temp ();
t.setParent (this);
}
}

public class Temp
{
private A _aObj;
Temp () {..}
void setParent (A aObj) {
_aObj = aObj;
}

void compute () {

// from here I need to access setObj(List l) on B and C....
}
}

Temp is a GUI class and hence compute () won't be called until a UI action takes place......

Appreciate your help !!
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
I guess you want to access setObj of B and C



Or you could instantiate separate objects for respective classes.

Hope this helps.
[ April 04, 2007: Message edited by: srikanth ramu ]
Ashok Paulraj
Ranch Hand

Joined: Jul 07, 2003
Posts: 78
the above code sample defines _aObj which is already defined in setParent(...)

Also, I could do an instanceof to determine the subclass of A but is there a neat way to do this avoiding instanceof.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sub class access