• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Question please answer

 
Yasser Shaikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this piece of code compile without any errors or exceptions???



The problem is when i tried ....
I got a runtime exception ...



Please Help !
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why you would get java.lang.ClassNotFoundException. Was your Basic class in a file named "Basic.java"?

The code you've posted won't compile because you're calling a non-static method, method(), from the static context of main. Please check to make sure you've posted the exact same code that you're running.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest, fastet way to find out if code will compile is to... compile it.

Have you tried that?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And try to compile it before you try to run it If you get compiler errors, you know to stop/
 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
method() is not static, you would need an instance of Basic on which to invoke that method. Or just mark it as static too.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harold Lime wrote:method() is not static, you would need an instance of Basic on which to invoke that method. Or just mark it as static too.
Don't go telling too many answers too quickly. Otherwise they never learn to work it out for themselves.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic