This discussion is archived
2 Replies Latest reply: Oct 13, 2012 7:00 AM by TPD-Opitz-Consulting-com RSS

Inheritence

932666 Newbie
Currently Being Moderated
Hi Guys, Hope Everything is going well.
We do know that It is not possible to create an object of a SUB CLASS from a SUPER CLASS. But suppose you are bound to create an OBJECT Of your SUB CLASS from that specific super class, in that Super Class. Is there any way to create it ? Please Help me. I will be grateful to you all.

Edited by: 929663 on Oct 13, 2012 3:02 PM
  • 1. Re: Inheritence
    sabre150 Expert
    Currently Being Moderated
    I don't really follow what your are asking. To my mind this does not really make any sense since an "OBJECT" is an "INSTANCE" then after your assertion that " It is not possible to create an INSTANCE of a SUB CLASS from a SUPER CLASS" how can you ask "But suppose you are bound to create an OBJECT Of your SUB CLASS from that specific super class". You have asserted it is not possible.

    Please elaborate on your requirement.
  • 2. Re: Inheritence
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    929663 wrote:
    We do know that It is not possible to create an object of a SUB CLASS from a SUPER CLASS.
    Where does your knowledge come from? The following works well with my copy of javac:
    public class A {
      public static A createB(){ //poor mans factory...
        return new B();
      }
    }
    class B extends A {
    }
    bye
    TPD

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points