Results 1 to 3 of 3
  1. #1
    er1c550n20 is offline Member
    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    Default 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);
    }
    }

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Hello,

    welcome to the forum.

    Please you code tags next time like one below"

    You need ";"

    Java Code:
    ...
    {
    		super(x,y)[COLOR="Red"];[/COLOR]
    		height = z;	
    	}
    ...
    cheers!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by er1c550n20 View Post
    Java Code:
    C:\jdk1.5\bin\InheritanceTest.java:22: ';' expected
            height = z; 
                   ^
    1 error
    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

  1. Inheritance method problem
    By Chasingxsuns in forum New To Java
    Replies: 3
    Last Post: 11-10-2009, 08:30 PM
  2. Problem with Inheritance
    By KronikAlkoholik in forum New To Java
    Replies: 4
    Last Post: 08-25-2009, 12:13 AM
  3. Inheritance example
    By kris4u4ever in forum New To Java
    Replies: 3
    Last Post: 03-21-2009, 02:53 PM
  4. inheritance
    By itaipee in forum New To Java
    Replies: 6
    Last Post: 01-20-2009, 08:18 PM
  5. Inheritance
    By mew in forum New To Java
    Replies: 1
    Last Post: 12-07-2007, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •