



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




➢ (^) Methods are members of classes which provide functionality for classes. ➢ We can write our own methods in the classes. ➢ (^) The functions performing on the data are known as methods. ➢ (^) When a method returns a value then the method itself takes the value. ➢ (^) A method will have its own copy of variable. ➢ (^) Skeleton of method: returnType methodName(parameter list) !signature/header {
} Example program: class test { static int max(int x, int y) { x++; if(x>y) return x; else return y; } public static void main(String args[]) { int a=10,b=15,c; c=max(a,b); System.out.println(c); } }
➢ (^) To call a method from main method it is needed to be maid static. ➢ When the method is called the value of actual parameters are copied in formal parameters which is the only parameter passing method in java. ➢ (^) The address of object in formal and actual parameter is Same. ➢ (^) String cannot be modiIied as it is immutable. ➢ (^) A method can also return an object. Example program: ➢ A method can have its object as the return type.
➢ (^) Whoever is calling a method is called as a caller or a method call. ➢ (^) The method which is called by a caller is known as called method. ➢ (^) The parameters/arguments passed in calling method are called as actual parameters. class test { static void update(int A[]) { A[0]=25; } public static void main(String args[]) { int A[]={2,3,4,5,6}; update(A); System.out.println(A[0]); } }
➢ (^) Compiler will call the corresponding method depending upon the parameter list.
➢ It is nothing but writing a single method which can run for number of parameters of same data types. ➢ (^) For example – void show(int …x) Where … represents the variable arguments. ➢ (^) It is similar to ellipsis in c/c++. ➢ (^) The parameters passed are converted into an array. ➢ (^) The parameters can be directly passed using an anonymous array. ➢ (^) Variable argument should always be the last parameter. ➢ (^) Printf is based on variable arguments in version 1.7 java.
➢ (^) Java programs can utilize command line arguments. ➢ (^) Dos Iile is used for command line arguments. ➢ There are different commands like.
➢ (^) A recursive method is the one which will call itself. ➢ (^) When the recursive function can not call itself further because of the base condition it will return back along the same path. ➢ (^) Not to make the program lengthy loops are used instead of recursive functions. ➢ (^) The recursions are used in problem solving.