Main method and constructor. In English

              Main method & Constructor











Content

1.Main method

2.Parameter & Arguments

3.Constructor


1.Main method ..........

The first method is the entry point for executing a java program. The main method can contain code to execute or call other methods and it can be placed in any class that is part of a program.



2.Parameter and Arguments ......... 

  • The parameter is the variable defined in the method declaration after the method name in parentheses. This includes primitive types like int, float, boolean and non-primitive or object types like array, string.

  • Values can be passed to method parameters during the method call. They are called arguments.


  

  • Data types can be used as return types. Must be returned using the return keyword. The output is given depending on the data type used. 




3.Constructor ............

  • A constructor is a method.
  • A constructor is a method created by the same name of the class, without a return type.
                                  Ex: -





  • The constructor is called when the object is run.



  • We code the things that need to run first in a class inside the constructor.
            Ex: -
                    class C {
                    C (string x) {
                    }
                    C c = new C ("Nimeshi");
                    }



Comments

Popular posts from this blog

Lambda expression in Java. In English

Loops in Java. In English

Conditions in java. In English