Class Methods are nothing but static methods which are called without an instance of the class where as Instance methods needs an instance of class .
For example:- public static void display() is an Class method
where as class A
{
public void display()
{
......................
}
public static void main(String[] args) {
A a = new A();
a.display();// Instance method
}
}
Class Methods
|
Instance Methods
|
Class
methods are methods which are declared as static. The method can be called
without creating an instance of the class
|
Instance
methods on the other hand require an instance of the class to exist before
they can be called, so an instance of a class needs to be created by using
the new keyword.
Instance methods operate on specific instances of classes. |
Class
methods can only operate on class members and not on instance members as
class methods are unaware of instance members.
|
Instance
methods of the class can also not be called from within a class method unless
they are being called on an instance of that class.
|
Class
methods are methods which are declared as static. The method can be called
without creating an instance of the class.
|
Instance
methods are not declared as static.
|
Enjoy Reading.
No comments:
Post a Comment