-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodsIn.java
More file actions
54 lines (47 loc) · 1.58 KB
/
MethodsIn.java
File metadata and controls
54 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// methods are block of code defined inside a class.
//methods are just functions which are defined insdie the body of the class.
// if you are creating a method of string type and retrurning another type of value it will five an error.
// ( the values of the actual argumetns are passed to the fromal arguments.)
// Syntax :- Access specifier _ return type _ method name _ (Arguments(Formal_arguments))
//{
// method body
//}
// Methods are declared outside the main body but called throguh them.
/*public class MethodsIn { //(void type method)
public static void main(String[]args){
System.out.println("code to represent method in java");
greetings();
}
//Access specifiers _ static keyword _ return type _ method name(parameters)
public static void greetings(){
System.out.println("code to represent void method in java");
System.out.println("hello goodmorning ! ");
}
}
*/
// method with return type of string value.
// retrunig a String value.
/*
public class MethodsIn {
public static void main (String[]args){
String pleasure = Greetings();
System.out.println(pleasure);
}
static String Greetings(){
String greets = "Have a nice day";
return greets ;
}
}
*/
/*
public class MethodsIn {
public static void main(String[]args){
int value = sum(5 , 7); // method call + actual arguments
System.out.println(value);
}
// method with arguments.
public static int sum(int a , int b){ // formal arguments( the values of the actual argumetns are passed to the fromal arguments.)
int c = a + b ;
return c ;
}
} */