Static methods vs Instance methods in Java

Java 8Object Oriented ProgrammingProgramming

In Java as we know that the behavior of any variable/method is defined by the keyword that is used in front of its declaration name. So one of the non-access modifiers is Static which can be used along with method as well as with variable.

Static methods as name states defined at the class level and could be accessed on the class name i.e no need of class object creation in order to access/call the static methods.

While on another hand if we do not uses the static keyword with variable/method than it belongs or categorized as instance method which is defined at instance level and need class object for their accessibility.

Also static methods exist as a single copy for a class while instance methods exist as multiple copies depending on the number of instances created for that particular class.

Static methods can't access instance methods/variables directly while instance methods can access static variables and static methods directly.

raja
Published on 04-Dec-2018 08:21:46
Advertisements