Java is a general programming language created in 1995.

More than 3 billion devices are powered by javaIts used in Desktop applications, mobile applications (Android apps are built using Java), web applications, Games (Minecraft’s desktop version is built using Java)Java being such a popular language boasts a huge communityIts easy to learn and simple to use. 

Java is a class based, object-oriented language. In this tutorial we are going to learn to how to call methods in Java.

java has classes that define a blueprint/template for a object. The object has state and behaviour. A objects state is stored in variables and its behaviour is defined using methods.

For Example:

Consider the following Java class ‘Car’, it defines two states the name and year (model year) of the car with a behaviour ‘drive’:

There are two kinds of methods

  • Non-static or instance methods.
  • Static or class methods.

How to call a Instance method

Consider the above-mentioned car class again with another method ‘car info’:

Car_info is a instance method, it is associated with an object. To invoke/call this function we need to create a object the class.

How to call a Static method

Consider the above-mentioned car class again with another method ‘car_info2’:

Car_info2 is static method, the static keyword is used in the declaration of the method. It is associated with the class. We do not need to instantiate a object to call this method.

Send us a feedback0/500

Do you like this article?
Yes
No