Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Invoking the Constructor of the Top Most Class in the Hierarchy from the Bottom most class

Reply
Thread Tools

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

 
 
H.MuthuKumaraRajan
Guest
Posts: n/a
 
      02-03-2004
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
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      02-03-2004
"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


 
Reply With Quote
 
 
 
 
Adam Maass
Guest
Posts: n/a
 
      02-03-2004

"H.MuthuKumaraRajan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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);
}
}


 
Reply With Quote
 
H.MuthuKumaraRajan
Guest
Posts: n/a
 
      02-04-2004
Thanks to every one for the response.

"Andrew Thompson" <(E-Mail Removed)> wrote in message news:<amITb.40584$(E-Mail Removed)>...
> "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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
css "div" bottom of window or bottom of content. Dan HTML 1 04-04-2008 09:40 AM
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
How do we know the memory arrangement using in microprocessors? Top-Bottom or Bottom-Top? Cuthbert C Programming 8 09-13-2006 12:09 PM
CSS to put text at bottom of browser window, or page bottom, whichever is lower? Noozer HTML 1 03-13-2006 10:35 AM
Invoking templatized base class constructor from templatized derived class constructor mrstephengross C++ 5 05-18-2005 07:12 PM



Advertisments