aspose file tools*
The moose likes Beginning Java and the fly likes Problem with constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with constructors" Watch "Problem with constructors" New topic
Author

Problem with constructors

Sujay Nadkarni
Ranch Hand

Joined: Jul 03, 2008
Posts: 34


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

Joined: Jul 03, 2008
Posts: 34
oops got it!!
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
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

Joined: Jun 28, 2008
Posts: 85
What did you get?Let me know.Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
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

Joined: Oct 13, 2005
Posts: 40064
    
  28
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

Joined: Jun 28, 2008
Posts: 85
Thanks Campbell.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with constructors