0

Hi,
I just wanted to know about instance method? If static modifier is not applied before does it makes it an instance method ? Plz give an example
Thanku

4
Contributors
3
Replies
21
Views
2 Years
Discussion Span
Last Post by newcoder310
0

Static methods are NOT instance methods! An instance method will operate on instance variables typically, and require an instance to run. A class static method is like a global function, but associated more closely with a class, especially if the class has static member variables.

1

If static modifier is not applied before does it makes it an instance method ?

Yes.

Votes + Comments
Sometimes the simplest answers are the best!
0

Below is a sample code snippet showing difference between static method and instance method.
Declaration
Static Method

class DetailsBean{
pubic static String setName(String name){
    this.name = name;
    }
}

Instance Method

class DetailsBean{
    pubic String setName(String name){
        this.name = name;
        }
    }

How to access

Static Method

public class User{
public void populateDetails(){
    DetailsBean.setName(name);
}
}

InstanceMethod

 public class User{
    public void populateDetails(){
        DetailsBean detailsBean = new DetailsBean();
        detailsBean.setName(name);
    }
 }

Hope it was helpful!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.