Results 1 to 4 of 4
Thread: Not sure...
- 08-20-2012, 03:03 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 10
- Rep Power
- 0
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?
- 08-20-2012, 04:03 AM #2
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
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.required int int, found no arguments
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.
- 08-20-2012, 04:56 AM #3
- 08-20-2012, 07:23 AM #4
Re: Not sure...
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks