Static and Non Static Method Intercall in Java -


I am clarifying my concepts on Java. My knowledge about Java is so far in the initial side, so please bear with me.

I am trying to understand the static method and the non-static method. I know -

  1. The static method can call another static method in the same class by its name.
  2. Only non-steak methods of the same class can call after creating static method. Example of class.
  3. Non-static method can call another static methion of the same class through the classname.Maneman - is it not certain that it is correct?

    My question is non static method about the other non-steak method of the same class. In class declaration, when we declare all the methods, can we call non-static class other non-static method of the same class?
    Please explain with examples. Thank you

    Your # 3, correct, you can call in a nonstandard way in a static manner Using .methodname.

    And your question is asking if you can call non-static methods in a class with other non-static methods, which is possible (and most commonly seen).

    For example:

      Public square fu {public fu () {first method (); Foo.staticMethod (); // This is a valid static method (); // It is also valid, you do not need to declare the class name because it is already in this class if you were calling "static method" from any other class, you will find this prefix with the name of this class Foo} Public Zero firstMethod () {System.out.println ("This is a non-static method that is being told from the constructor."); SecondMethod (); } Public Zero secondMethod () {System.out.println ("This is a non-static method called non-static method"); } Public static zero static (method) {System.out.println ("This is static method, static method"); }}    

Comments