Java: Static Methods and Instance Methods

Static Methods

They are class methods. They are not associated with a particular object. Simply put, you don’t have to declare a new object based on a class to use this method.

Example:

String t = String.valueOf(n);

Instance Methods

This operates on an object (an instance of a class). They utilize the instance variables of that object. Simply put, you need to create a new object to make use of this kind of method.

Example:

String s = new String("Coding is an awesome career!");
int n = s.length();

Further reading:

  1. http://www.dummies.com/how-to/content/what-is-the-static-keyword-in-java.html
  2. http://www.leepoint.net/notes-java/flow/methods/50static-methods.html

 

August 29, 2014

Posted In: Information Technology

Tags: , ,

Leave a Comment