• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting access to grandfather's constructor

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have a class named Father the extends Grandfather , inside this class Father I have an inner class named Son, how can I get access the Grandfather constructor from the Son class?(code please)
Thanks
Shay Gaghe
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shay Gaghe:
I have a class named Father the extends Grandfather , inside this class Father I have an inner class named Son, how can I get access the Grandfather constructor from the Son class?(code please)


This is the code for constructor calling from Son. However, if Father extends GrandFather and Son is a non-static inner class, its creation by default will call all the constructors from top order; GrandFather, Father and then Son. Is this what you want?

HTH,
- Manish
 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
In my particular case I have class named A that extends Jlabel, and in the A I have another class named B that extend Jlabel as well. in order to perform image displaying from B I meant to call (by super(image) to the Jlabel constructor but I cant because A is the superclass, how can I do such a performance calling the Jlabel constructor(which is the A superclass)?
(I don�t know why its not calling the B superclass which is jlabel as well, I try it but I receive compiling error)
Thanks
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shay Gaghe:
In my particular case I have class named A that extends Jlabel, and in the A I have another class named B that extend Jlabel as well. in order to perform image displaying from B I meant to call (by super(image) to the Jlabel constructor but I cant because A is the superclass, how can I do such a performance calling the Jlabel constructor(which is the A superclass)?
(I don�t know why its not calling the B superclass which is jlabel as well, I try it but I receive compiling error)


OK.
In this case you need to ensure 2 things
1) Class A has default, no parameter constructor, else call its parameterized constructor appropriately.
2) While calling super(Icon image) in the inner class constructor, image shouldn't be an instance variable of the inner class B, or its outer class A.
HTH,
- Manish

[This message has been edited by Manish Hatwalne (edited October 15, 2001).]
 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manish
itried to run this code and i got the following error:

errors:
"Father.java": Error #: 300 : variable Father not found in class Father.Son at line 18, column 7
"Father.java": Error #: 479 : illegal qualifier; class java.lang.Object is not an inner class at line 18, column 14

thanks
 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , look in this please:

thanks
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shay Gaghe:
I have a class named Father the extends Grandfather , inside this class Father I have an inner class named Son, how can I get access the Grandfather constructor from the Son class?(code please)

You can't, except by creating a new Grandfather object. There is no way to directly call a constructor, with one exception: in the very first line of a constructor, you can call a different constructor in the same class by calling this() or the superclass constructor by calling super().
- Peter
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first code you had posted (Father - Son) compiled on machine w/o any problem. (win 2k, JDK 1.3)
As for your second code snippet, since outer class extends JPanel and inner class extends JLabel, it shouldn't be a problem. Like Peter said you'll neeed to call it in the constructor as the very first line, with a value which is not an instance variable of that class.
Here is a code snippet I have tried on my machine which compiles w/o a problem. Of course, you'll need to make sure that Icon img in the outer class holds a proper value.

Let us know if it helps,
- Manish
[This message has been edited by Manish Hatwalne (edited October 15, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic