Forums Register Login

Non static method

+Pie Number of slices to send: Send


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?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
Thanks Henry..
+Pie Number of slices to send: Send
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.
Get off me! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 651 times.
Similar Threads
weird
Doubt with declaring local variables as satic
Reason for Compile-Time error
static variable within a non-static method
local variable!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:55:25.