• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Basic Question please answer

 
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 !
 
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.
 
lowercase baba
Posts: 12893
63
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?
 
Marshal
Posts: 70234
282
  • 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/
 
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
Marshal
Posts: 70234
282
  • 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.
    Bookmark Topic Watch Topic
  • New Topic