This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me with Java.  RSS feed

 
Rui Sousa
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I´m here again boring you (hope not)

there is the thing: i´m running this java code in comand promt but it gives me this error:

Main method not found in class DrumKit, please define the main method as:
public static void main(String[] args)

There is my code:
class DrumKit{

boolean topHat = true;
boolean snare = true;

void playSnare(){
System.out.println("bang bang ba-bang");
}
void playTopHat(){
System.out.println("ding ding da-ding");
}
}

class DrumKitTestDrive{
public static void main(String[] args){

DrumKit d = new DrumKit();

d.playSnare();
d.snare=false;
d.playTopHat();
if(d.snare == true){
d.playSnare();
}
}
}

thanks for your time.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rui,

Welcome to CodeRanch!

Please, UseCodeTags. It makes reading the code much easier.

Coming to your question - the error is self explanatory.

However, I'm wondering - how are you running your code? Because, I can see that there is main method in DrumKitTestDrive class.

Are you running your code as
or

Maybe you are running as second command mentioned above - which is giving error regarding main method.

I hope this helps.
 
Rui Sousa
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:Hi Rui,

Welcome to CodeRanch!

Please, UseCodeTags. It makes reading the code much easier.

Coming to your question - the error is self explanatory.

However, I'm wondering - how are you running your code? Because, I can see that there is main method in DrumKitTestDrive class.

Are you running your code as
or

Maybe you are running as second command mentioned above - which is giving error regarding main method.

I hope this helps.



Thanks, appreciate your help, that was the issue.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!