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

 

Please follow and like us:
0

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

August 29, 2014

Posted In: Information Technology

Tags: , ,

Leave a Comment