Skip to content

Commit f12b931

Browse files
committed
Add JavaDocs, Overloading, and Return Types example code
1 parent 446f42d commit f12b931

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.codefortomorrow.intermediate.chapter11.examples;
2+
3+
public class JavaDocs {
4+
/**
5+
* Returns the average of two doubles
6+
* @param a first double
7+
* @param b second double
8+
* @return the average of two doubles
9+
*/
10+
public static double average(double a, double b) {
11+
return (a + b) / 2;
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.codefortomorrow.intermediate.chapter11.examples;
2+
3+
public class Overloading {
4+
public static void main(String[] args) {
5+
// call 2-arg sum
6+
System.out.println(sum(2, 3)); // prints 5
7+
8+
// call 3-arg sum
9+
System.out.println(sum(1, 4, 7)); // prints 12
10+
}
11+
12+
public static int sum(int a, int b) {
13+
return a + b;
14+
}
15+
16+
public static int sum(int a, int b, int c) {
17+
return sum(a, b) + c;
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codefortomorrow.intermediate.chapter11.examples;
2+
3+
public class ReturnTypes {
4+
public static void main(String[] args) {
5+
printSum(5, 4);
6+
int myNumber = sum(5, 4) / 2;
7+
System.out.println(myNumber);
8+
}
9+
10+
public static void printSum(int a, int b) {
11+
System.out.println(a + b);
12+
}
13+
14+
public static int sum(int a, int b) {
15+
return a + b;
16+
}
17+
}

0 commit comments

Comments
 (0)