• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with constructors

 
Sujay Nadkarni
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
oops got it!!
 
Max White
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
What did you get?Let me know.Thanks.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Campbell.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic