As we've already discussed that we can access 'static' methods without creating any objects outside the class by calling the 'static' method using ClassName.methodName( ) statement.
Lets implement this on Eclipse IDE:
1. Create a class 'StaticMethodDemo' under 'twelve_package' package of 'Twelve Project' project as shown below:
5. Save and Run the 'AccessStaticMethod' class
6. Observe that the output is displayed as shown below:
7. Create 'DifferentPackageAccess' class under 'different_package' as shown below:
10. Observe that the output is displayed in console as shown below:
Download this project:
Click here to download this project containing the class files used in this post (You can download the project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
'static' methods can only call 'static' methods will be explained with an example in next post.