Invoking the Constructor of the Top Most Class in the Hierarchy from the Bottom most class

Discussion in 'Java' started by H.MuthuKumaraRajan, Feb 3, 2004.

  1. Hi,
    Is it possible to invoke the constructor of the Top Most Class in the Hierarchy
    from the Bottom most class.
    for eg.,
    class A {
    long l;
    A(long l) {
    this.l = l;
    }
    A(){}
    }

    class B extends A {
    String s;
    B(String s) {
    this.s=s;

    }
    B(){}
    }

    public class C extends B {
    C(long l){
    // TO INVOKE THE CONSTRUCTOR WITH LONG PARAMETER IN CLASS A
    }
    }
    I want to invoke the Constructor (with long parameter) in class A from class C,
    How to do this?
    Thanks in advance,
    Rajan
    H.MuthuKumaraRajan, Feb 3, 2004
    #1
    1. Advertising

  2. "H.MuthuKumaraRajan" ...
    > Hi,
    > Is it possible to invoke the constructor of the Top Most Class in the

    Hierarchy
    > from the Bottom most class.


    Yes.

    > for eg.,


    There may be other ways, but this works
    ______________________
    class A
    {
    long l;

    A(long l)
    {
    this.l = l;
    }

    A(){}
    }

    class B extends A
    {
    String s;

    B(String s)
    {
    this.s=s;
    }

    B(long l)
    {
    super(l);
    }

    B(){}
    }

    class C extends B
    {
    C(long l)
    {
    super(l);
    // TO INVOKE THE CONSTRUCTOR WITH LONG PARAMETER IN CLASS A
    }
    }
    ______________________
    HTH

    --
    Andrew Thompson
    * http://www.PhySci.org/ Open-source software suite
    * http://www.PhySci.org/codes/ Web & IT Help
    * http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Feb 3, 2004
    #2
    1. Advertising

  3. H.MuthuKumaraRajan

    Adam Maass Guest

    "H.MuthuKumaraRajan" <> wrote in message
    news:...
    > Hi,
    > Is it possible to invoke the constructor of the Top Most Class in the

    Hierarchy
    > from the Bottom most class.
    > for eg.,
    > class A {
    > long l;
    > A(long l) {
    > this.l = l;
    > }
    > A(){}
    > }
    >
    > class B extends A {
    > String s;
    > B(String s) {
    > this.s=s;
    >
    > }
    > B(){}
    > }
    >
    > public class C extends B {
    > C(long l){
    > // TO INVOKE THE CONSTRUCTOR WITH LONG PARAMETER IN CLASS A
    > }
    > }
    > I want to invoke the Constructor (with long parameter) in class A from

    class C,
    > How to do this?
    > Thanks in advance,
    > Rajan



    You need a constructor in B that takes a long:

    class B extends A
    {
    B (long l)
    {
    super(l);
    }
    }


    And now, you can chain the long constructor in C:

    class C extends B
    {
    C(long l)
    {
    super(l);
    }
    }
    Adam Maass, Feb 3, 2004
    #3
  4. Thanks to every one for the response.

    "Andrew Thompson" <> wrote in message news:<amITb.40584$>...
    > "H.MuthuKumaraRajan" ...
    > > Hi,
    > > Is it possible to invoke the constructor of the Top Most Class in the

    > Hierarchy
    > > from the Bottom most class.

    >
    > Yes.
    >
    > > for eg.,

    >
    > There may be other ways, but this works
    > ______________________
    > class A
    > {
    > long l;
    >
    > A(long l)
    > {
    > this.l = l;
    > }
    >
    > A(){}
    > }
    >
    > class B extends A
    > {
    > String s;
    >
    > B(String s)
    > {
    > this.s=s;
    > }
    >
    > B(long l)
    > {
    > super(l);
    > }
    >
    > B(){}
    > }
    >
    > class C extends B
    > {
    > C(long l)
    > {
    > super(l);
    > // TO INVOKE THE CONSTRUCTOR WITH LONG PARAMETER IN CLASS A
    > }
    > }
    > ______________________
    > HTH
    H.MuthuKumaraRajan, Feb 4, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    1
    Views:
    8,336
    ainigma
    Apr 4, 2008
  2. Noozer
    Replies:
    1
    Views:
    7,099
    Carolyn Marenger
    Mar 13, 2006
  3. mrstephengross
    Replies:
    5
    Views:
    584
    Larry I Smith
    May 18, 2005
  4. Cuthbert
    Replies:
    8
    Views:
    417
    Ancient_Hacker
    Sep 13, 2006
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,190
Loading...

Share This Page