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.
- 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.
- A constructor is a method.
- A constructor is a method created by the same name of the class, without a return type.
- The constructor is called when the object is run.
- We code the things that need to run first in a class inside the constructor.
class C {
C (string x) {
}
C c = new C ("Nimeshi");
}
Comments
Post a Comment