aspose file tools*
The moose likes Beginning Java and the fly likes Basic Question please answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Basic Question please answer" Watch "Basic Question please answer" New topic
Author

Basic Question please answer

Yasser Shaikh
Greenhorn

Joined: Oct 01, 2008
Posts: 21
Will this piece of code compile without any errors or exceptions???



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



Please Help !


~~yr[:_:]s~~
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
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

Joined: Oct 02, 2003
Posts: 11494
    
  16

The easiest, fastet way to find out if code will compile is to... compile it.

Have you tried that?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
And try to compile it before you try to run it If you get compiler errors, you know to stop/
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
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

Joined: Oct 13, 2005
Posts: 40027
    
  28
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Basic Question please answer