java - I am Always getting the Instance of Parent Class.But i need a child one -
i want instance of child class getting parent class instance can explain me why?? according xmltype id getting instace of children(string or anyuri) etc.but in conditions need child class instance.
code::
public abstract class wstype public final static wstype getinstance(int xmltypeid) { switch (xmltypeid) { case string: return wsstringtype2.getinstance(); //**here getting parent class calling instance of wsstringtype2.** case anyuri: return wsanyuritype2.getinstance(); } } public final static wstype getinstance(int xmltypeid, string data) throws xcallexception { wstype wsdata = wstype.getinstance(xmltypeid); /**/calling happening here** } } public class wsstringtype extends wstype { protected string m_data; public wsstringtype() { m_data = "'"; } public wsstringtype(string name){ m_data=name; } public static wsstringtype getinstance() { return new wsstringtype(); } } class wsstringtype2 extends wsstringtype { public wsstringtype2() { m_data = "'"; } public static wsstringtype2 getinstance() { return new wsstringtype2(); } public wsstringtype2(string newvalue){ super(newvalue); } }
the return type of getinstance(int xmltypeid)
wstype
parent. can cast wsstringtype2
because wsstringtype2
extends wsstringtype
, wsstringtype
extends wstype
wstype wt = wstype.getinstance(string); wsstringtype2 wt2 = null; if (t instanceof wsstringtype2) { wt2 = (wsstringtype2) wt; }
Comments
Post a Comment