hello i use netbeans and i was working on an example program for a class motorcycle
which goes
Motorcycle = new Motorcycle
in this line the program returned an error that said Motorcycle cant be instantiated. pls what does dis mean
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hello i use netbeans and i was working on an example program for a class motorcycle
which goes
Motorcycle = new Motorcycle
in this line the program returned an error that said Motorcycle cant be instantiated. pls what does dis mean
Last edited by jamal; September 13th, 2010 at 06:35 PM. Reason: [SOLVED]
When you create a new Object, you need two things.
1) a variable name
2) a constructor
So, if the Motorcycle constructor looked like this:
public Motorcycle() { ... }
You need to say:
In this, motor is our variable name and Motorcycle() is our call to Motorcycle's constructor that I mentioned above.Motorcycle motor = new Motorcycle();
Tell me if that helps.
jamal (September 13th, 2010)
Please post the code for the Motorcycle class. There are a variety of reasons why the Motorcycle class can't be instantiated:
1. The class is either an interface or declared abstract
2. You're using the wrong syntax (as suggested by aussiemcgr)
3. The class has no accessible constructors (for example a private or protected constructor)
jamal (September 13th, 2010)
Really grateful 4 d assistance it really helped but i got anoda issue wich i dont quite undastand anytime i write a code like
public static void main (String args[]) {
i always get illegal start of expression, and also with something like dis
void showAtts() {
Last edited by jamal; September 13th, 2010 at 04:40 PM. Reason: spelling error
If you're making a method you have to include private or public BEFORE the return.
public void showAtts(){} //or private void showAtts(){}
Here is how to set up a method:
See this website for more information Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Last edited by Brt93yoda; September 13th, 2010 at 05:37 PM.
Last edited by jamal; September 13th, 2010 at 05:32 PM. Reason: incomplete
I don't know why the web page is freaking out. Anyways, all of it depends on what you are trying to do. If I were you I would go through some more tutorials. Here is a good place to start: http://download.oracle.com/javase/tutorial/
I'm assuming what you're trying to do, so please correct me if I am going in the wrong direction.
public void showAtts(int motorcycleNumber){ if (motorcycleNumber == 1) { //do motorcycle 1 things } if (motorcycleNumber == 2) { //do motorcycle 2 things } //ETC... }
Last edited by Brt93yoda; September 13th, 2010 at 05:44 PM.
Thanks very much this program is from a text book am reading and it is part of the test programs but each time i write the entire program i dont make any head out of it, i always get error replies. for the showatts i already created the variables indicating the make and color of the motorcycle as follows
public void showAtts() { System.out.println("This motorcycle is a " + color +" " + make); if (engineState == true) System.out.println("The engine is on."); else System.out.println("The engine is off."); public static void main (String args[]) { Motorcycle motor = new Motorcycle(); motor.make = "Yamaha RZ350"; motor.color = "Yellow"; System.out.println("Calling showAtts..."); motor.showAtts(); System.out.println("........"); System.out.println("Starting engine..."); motor.startEngine(); System.out.println("........"); System.out.println("Calling showAtts..."); motor.showAtts(); System.out.println("........"); System.out.println("Starting engine..."); motor.startEngine(); } }
now for each step i get illegal start of expression and in the case of the showAtts i get symbol not found
i hope this would give u a beta idea of my problem. really appreciate the time
Last edited by jamal; September 13th, 2010 at 05:54 PM. Reason: incomplete
This should work. I strongly suggest that you go through the tutorials in the link I posted earlier.
public class motorcycle { static String make,color; static boolean engineState; public static void startEngine(){ engineState = true; } public static void showAtts() { System.out.println("This motorcycle is a " + color +" " + make); if (engineState == true) System.out.println("The engine is on."); else System.out.println("The engine is off."); } public static void main (String args[]) { make = "Yamaha RZ350"; color = "Yellow"; System.out.println("Calling showAtts..."); motorcycle.showAtts(); System.out.println("........"); System.out.println("Starting engine..."); motorcycle.startEngine(); System.out.println("........"); System.out.println("Calling showAtts..."); motorcycle.showAtts(); System.out.println("........"); System.out.println("Starting engine..."); motorcycle.startEngine(); } }
Last edited by Brt93yoda; September 13th, 2010 at 06:06 PM.
jamal (September 13th, 2010)
REALLY GRATEFUL