Results 1 to 4 of 4

Thread: Not sure...

  1. #1
    Ray
    Ray is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Not sure...

    Okay, I'm pretty new to java, just learning about classes and objects.
    So I have a super class: bicycle
    subclasses: mountainbike
    Here they are:
    public class Bicycle
    {
    public int speed;
    public int gear;

    public Bicycle(int startSpeed, int startGear)
    {
    speed = startSpeed;
    gear = startGear;
    }

    public void changeSpeed(int newSpeed)
    {
    speed = newSpeed;
    }

    public void changeGear(int newGear)
    {
    gear = newGear;
    }

    }

    and
    public class MountainBike extends Bicycle
    {
    private int chairHeight;

    public MountainBike(int newChairHeight)
    {
    chairHeight = newChairHeight;
    }
    }
    When attempting to compile MountainBike, i get:
    constructor bicycle in class bicycle cannot be applied to given types
    required int int, found no arguments
    What arguments do I need?
    How do i make it work :s
    Noob question I know.

    Finally, lets say I have another subclass called roadbike.

    I can't have a userinterface class that extends both roadbike and mountainbike.
    Like, lets say the userinterface asks, "which bike do you want to ride?"
    well i mean... how do you do it?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Not sure...

    Please post the full text of the compiler error message that shows the source line where the error is.

    Please edit your post and wrap the code in code tags:
    BB Code List - Java Programming Forum

    required int int, found no arguments
    The compiler could not find a call to the defined constructor for the Bicycle (with int int args) and is trying to generate a call to a constructor with no arguments and can not find a definition for that constructor.
    Either call the one with (int int) or define a constructor without any args.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: Not sure...

    Quote Originally Posted by Ray View Post
    Finally, lets say I have another subclass called roadbike.

    I can't have a userinterface class that extends both roadbike and mountainbike.
    Like, lets say the userinterface asks, "which bike do you want to ride?"
    well i mean... how do you do it?
    Not really sure what you are trying to do but Java does not support multiple inheritance. So class C cannot extend class A and class B.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Not sure...

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

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