• Post Reply Bookmark Topic Watch Topic
  • New Topic

Non static method  RSS feed

 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why the above code does not give compilation error??
method is non static method and calling from static main..

Can you refer non static method from static content in java?
 
Henry Wong
author
Sheriff
Posts: 23284
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandana Garlapati wrote:
why the above code does not give compilation error??
method is non static method and calling from static main..

Can you refer non static method from static content in java?


You can't refer to an instance method from a static method, without using an instance. In this case, you are using an instance, so it is okay.

Henry
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry..
 
Atwal Usha
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you would have accessed the method directly from within the main method then it would have resulted in compile time error. To do that you will have to declare that method static however in that case it would no more be an instance method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!