0

Can a non-static method be accessed from a static method? And can a static method be accessed from a non-static method?

3 Answers 3

6

A static method can be accessed from a non-static, but not the other way around. If you're inside a static method, you can only access a non-static method if you have an instance of an object on which to call the method.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Can a non-static method be accessed from a static method? No because an object is required to access non-static method and there are chances that an object is not available while accessing a static method

  2. can a static method be accessed from a non-static method? Yes.

Comments

0

To access a non-static method, you need to have an instance of an object. If you are inside a static method, then you are not able to call non-static method, because, per definition, you are not "inside" an object (so you don't have any object to call this method on). You can however call non-static methods from static if you have a reference to the object you want to call the non-static method on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.