| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
returnType nameOfMethod() {
//Method body
}
int mySum(int a, int b) {
int c = a+b;
return c; //Return value
}
Calc obj = new Calc(); //Object Creation obj.mySum(a , b); //Method call upon an object
class calculate{
int sum(int a,int b){
return a+b;
}
class calculate{
int sum(int a,int b){
return a+b;
}
public static void main(String[] args) {
calculate obj = new calculate();
int c = obj.sum(5,4);
System.out.println(c);
}
}
Output : 9
Note: In the case of Arrays, the reference is passed. The same is the case for object passing to methods.
package com.company;
public class cwh_31_methods {
static int logic(int x, int y){
int z;
if(x>y){
z = x+y;
}
else {
z = (x +y) * 5;
}
x = 566;
return z;
}
public static void main(String[] args) {
int a = 5;
int b = 7;
int c;
// Method invocation using Object creation
//cwh_31_methods obj = new cwh_31_methods();
//c = obj.logic(a, b);
c = logic(a, b);
System.out.println(a + " "+ b);
int a1 = 2;
int b1 = 1;
int c1;
c1 = logic(a1, b1);
System.out.println(c);
System.out.println(c1);
}
}
Handwritten Notes: Click to Download
Ultimate Java Cheatsheet: Click To Download
| Back | FazBrowse Home | New Git URL |