• 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

Problem with constructors

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is my code..
i get this error :
Inheritancetest.java:21: cannot find symbol
symbol : constructor Box()
location: class Box
{
^
1 error

Help!!

[edit]Add code tags. CR[/edit]
[ July 03, 2008: Message edited by: Campbell Ritchie ]
 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops got it!!
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what i know,when you extend a class,you should call the superclass constructor from the subclass constructor.So your subclass code should be like-

class Box1 extends Box
{
int k;
Box1(int width,int height,int breadth)
{
i=width;
j=height;
k=breadth;
super(i,j);
}


Let's see what others have to say!!!
 
Max White
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you get?Let me know.Thanks.
 
Marshal
Posts: 79049
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Max White:
From what i know,when you extend a class,you should call the superclass constructor from the subclass constructor.

You have to call the superclass constructor first.

The two classes do not actually extend each other properly; they have different i and j variables. If you declare a field in the superclass, you oughtn't to declare it again in the subclass.
 
Campbell Ritchie
Marshal
Posts: 79049
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to JavaRanch ( ) Sujay Nadkarni.

Please use the code button below the message box for quoted code; I have added it to your 1st posting so you can see how much better it looks.
[ July 03, 2008: Message edited by: Campbell Ritchie ]
 
Max White
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell.
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic