KnowledgeBoat Logo
LoginJOIN NOW

Computer Applications

Explain static and non-static methods.

User Defined Methods

30 Likes

Answer

Static methods are created with static keyword in their method prototype as shown below:

public static return-type method-name(parameter-list)
{
    Method-body
}

Static methods can be called directly using class name but they can't access instance variables and non-static methods of the class.

The non-static methods are created without the static keyword in their method prototype as shown below:

public return-type method-name(parameter-list)
{
    Method-body
}

An instance of the class is required to call non-static methods.

Answered By

17 Likes


Related Questions