Question:

Java: What is a class method?

by  |  earlier

0 LIKES UnLike

Can you give an example of how it is used in java?

I know the definition of the class method:

"A method that is invoked without reference to a particular object. Class methods affect the class as a whole, not a particular instance of the class."

 Tags:

   Report

1 ANSWERS


  1. They are static methods.As you stated we don't need any objects to access those methods(but can access using objects also).But you have to note down the following.Static methods can operate only on other static methods and they cannot use this or super() anyway.

    example.

    class StaticDemo

    {

    static int sumNumbers(int a,int b)

    {

    return a+b;

    }

    public static void main(String args[])

    {

    System.out.println("Accessing without any object: ");

    System.out.println(sumNumbers(10,20)...

    System.out.println("Accessing with an object: ");

    StaticDemo s=new StaticDemo();

    System.out.println(s.sumNumbers(20,3...

    }

    }

      

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.