Results 1 to 3 of 3
Thread: inheritance problem
- 03-10-2010, 05:46 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 9
- Rep Power
- 0
inheritance problem
guys how to remove error from this prog
it says C:\jdk1.5\bin\InheritanceTest.java:22: ';' expected
height = z;
^
1 error
class Room
{
int length;
int breadth;
Room(int x, int y)
{
length = x;
breadth = y;
}
int area()
{
return(length*breadth);
}
}
class BedRoom extends Room
{
int height;
BedRoom(int x, int y, int z)
{
super(x,y)
height = z;
}
int volume()
{
return(length*breadth*height);
}
}
public class InheritanceTest
{
public static void main (String args[])
{
BedRoom room1 = new BedRoom(14,12,10);
int area1 = room1.area();
int volume1 = room1.volume();
System.out.println("Area1 = :"+area1);
System.out.println("Volume1 = :"+volume1);
}
}
- 03-10-2010, 05:55 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Hello,
welcome to the forum.
Please you code tags next time like one below"
You need ";"
cheers!Java Code:... { super(x,y)[COLOR="Red"];[/COLOR] height = z; } ...
- 03-10-2010, 06:01 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Always read the details of the compiler error diagnostics: the caret '^' points to the end of 'height' wich is one token to the compiler (a name); it didn't expect that token, it expected a semi-colon and it said so. Go back in your source text and check where the compiler could've wanted to see a semi-colon.
kind regards,
Jos
Similar Threads
-
Inheritance method problem
By Chasingxsuns in forum New To JavaReplies: 3Last Post: 11-10-2009, 08:30 PM -
Problem with Inheritance
By KronikAlkoholik in forum New To JavaReplies: 4Last Post: 08-25-2009, 12:13 AM -
Inheritance example
By kris4u4ever in forum New To JavaReplies: 3Last Post: 03-21-2009, 02:53 PM -
inheritance
By itaipee in forum New To JavaReplies: 6Last Post: 01-20-2009, 08:18 PM -
Inheritance
By mew in forum New To JavaReplies: 1Last Post: 12-07-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks