OO Programming with Java


Advanced Concepts

  1. abs is an operation that belongs to a class:
public class Funs {
  public int abs(int x) { return (x>=0)?x:-x; }
  public static void main(String[] args) {
    System.out.println(new Funs().abs(-3));
  }
}

Notice the ternary/inline expression (condition)?trueValue:falseValue.


2 - 17