Calling a Method in Java Program
Calling a method in Java mainly involves of two basic steps:
1. You have to create an object to the class to which the method belongs.
Syntax for the above step : Classname obj = new Classname();
Example: First f = new First();
Here "First" is the classname and 'f' is the object created to that class.
2.Now after creating an object you can call any method using the notation "object.methodname();"
Therefore for the above example the calling goes like this : 'f.method'.
Here 'f' is the object we created.
1. You have to create an object to the class to which the method belongs.
Syntax for the above step : Classname obj = new Classname();
Example: First f = new First();
Here "First" is the classname and 'f' is the object created to that class.
2.Now after creating an object you can call any method using the notation "object.methodname();"
Therefore for the above example the calling goes like this : 'f.method'.
Here 'f' is the object we created.