Inheritance not working

前端 未结 4 1561
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 06:29

From my code I want my bedroom class to inherit length and breadth from the superclass - room. I have filled the errors in the respective lines within comments. I am getting

相关标签:
4条回答
  • 2021-01-17 07:07
    • Constructors' name must match class name, but since Java is case-sensitive Bedroom is not valid name for constructor in BedRoom class.
    • Also constructors doesn't have return type so remove void from it.

    In other words replace

    public void Bedroom(int x, int y, int z) {
    //     ^^^^    ^ 
    

    with

    public BedRoom(int x, int y, int z) {
    
    0 讨论(0)
  • 2021-01-17 07:08

    Change to

     public void BedRoom(int x,int y,int z)
    

    As for java Bedroom is not same as BedRoom

    0 讨论(0)
  • 2021-01-17 07:09

    You have simply misspelled BedRoom as Bedroom in the constructor declaration. (Correcting this would give you a more simple-to-understand error message about the problem that @HovercraftFullOfEels mentions: constructors do not have a return type.)

    0 讨论(0)
  • 2021-01-17 07:31

    Your BedRoom class has a pseudo-constructor not a real constructor. Constructors don't return anything, not void not anything. Get rid of that void statement.

    Change

    public void Bedroom(int x,int y,int z)
    

    to

    public BedRoom(int x,int y,int z) // also capitalize correctly
    
    0 讨论(0)
提交回复
热议问题