CONTENTS
Obj obj = new Obj();
do(obj);
void do(Obj objArg) {
...
}
public class IntMessageQueueOfCapacityOne {
private int contents;
private boolean available = false;
public synchronized int get() {
while (available == false) {
try {
wait();
} catch (InterruptedException e) { }
}
available = false;
notifyAll();
return contents;
}
public synchronized void put(int value) {
while (available == true) {
try {
wait();
} catch (InterruptedException e) { }
}
contents = value;
available = true;
notifyAll();
}
}
java [-options] class [arguments] or java [-options] -jar jarfile [arguments]
Main-Class: classname
/* Assume that Circle and Triangle are subclasses of Shape */
Circle c = new Circle();
Triangle t = new Triangle();
/* Here, instances of Circle and Triangle are being upcasted
to Shape
*/
Shape[] shapes = {c, t};
/* In the following snippet of Java code, Java does not know at compile
time whether shapes[i] is an instance of Circle or Triangle
Polymorphism ensures that Java does not *need* to know this
statically, i.e. at compile time
Obviously, calculateArea() will be implemented differently by the
subclasses of Shape, i.e. Circle, Triangle, etc.
However, the compiler does not need to check what subtype of Shape
it is dealing with and bind to the method of the appropriate subclass,
i.e., Circle.calculateArea(), Triangle.calculateArea(), etc.
Instead, Java will automatically determine at runtime that shapes[1] is
an instance of Triangle and use dynamic binding (also known as
late binding or runtime type identification RTTI) to bind the method
call to Triangle.calculateArea()
Since every sublclass of Shape has the ability to calculate its area,
this program invokes Shape.calculateArea() without worrying about the
specific subclass at hand
Thus, polymorphism allows the following code to be more extensible since
it will not impacted when new subclasses are added to the Shape hierarchy
*/
for (int i = 0; i < count; i++) {
System.out.println(shapes[i].calculateArea());
}
log4j.rootLogger=DEBUG, myLogFile
log4j.appender.myLogFile=org.apache.log4j.RollingFileAppender
log4j.appender.myLogFile=mylog.log
log4j.appender.myLogFile.threshold=WARN