A method with no parameters and no return value, declared with the public void method name;
A method with no return value, declared with the public void method name;
A method with a parameter that returns a value, declared with the public int method name (int i,int n), (int is the data type of the parameter or other data type, for example: String, char, double, int).
Instance:
//Defining Classes Public classtest{//method of no parameter return value Public voideat () {System.out.println ("I was eating." "); } //methods with no return value for parameters Public voidChengintIintN) {System.out.println (i*N); } //methods of having a parameter return value Public intGetage (inta) { returnA; } Public Static voidMain (string[] args) {Test Myclass=NewTest ();//Creating ObjectsMyclass.eat ();//Calling MethodsMyclass.cheng (9,9);//Calling MethodsSystem.out.println (Myclass.getage (18));//Calling Methods }}
Method parameters and return values in JAVA classes