File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
src/com/codefortomorrow/intermediate/chapter11/examples Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments