KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanselexample > Example


1 package org.hanselexample;
2
3 /**
4  * Example class that is tested by the ExampleTest class.
5  * This implements two methods and has one inner class.
6  *
7  * @author Niklas Mehner
8  */

9 public class Example {
10
11     /**
12      * The method returns the absolute value of an int.
13      * @param i Int.
14      * @return Absolute value of i.
15      */

16     public int abs(int i) {
17         if (i > 0) {
18             return i;
19         } else {
20             return -i;
21         }
22     }
23  
24     /**
25      * This method returns the sum of two numbers.
26      * @param a First addend.
27      * @param b Second addend.
28      * @return Sum of a and b.
29      */

30     public int add(int a, int b) {
31         return new ExampleInner().add(a, b);
32     }
33
34     /**
35      * The add method delegates the call to this class to
36      * test the coverage of inner classes.
37      */

38     private class ExampleInner {
39        
40         /**
41          * This method returns the sum of two numbers.
42          * @param a First addend.
43          * @param b Second addend.
44          * @return Sum of a and b.
45          */

46        public int add(int a, int b) {
47             return a + b;
48        }
49     }
50 }
51
Popular Tags