OOP Java Shortcut
OOP Java Shortcut
in Java
Object is characterized by
• State (defined by values of instance variables in Java)
• Behaviour (defined by instance methods in Java)
• Identity (defined by memory location in Java)
Object = Instance = Specimen = ...
• Instance variable (Java terminology) = (Object) field
= Property = Attribute = ...
• Method = Subroutine = Function / Procedure = ...
Object
Example.
public int compareTo (Object o)
is a method in Comparable interface. Making a class
Comparable (by implementing compareTo) gives a lot
of API methods for free, e.g. sort, max, min, ...
o1.compareTo(o2) < 0 , if o1 is less than o2
== 0 , if o1 equals to o2
> 0 , if o1 is greater than o2
Examples
Pets.java
Phones.java
Num.java
Complex.java