Escolar Documentos
Profissional Documentos
Cultura Documentos
Platform-dependent
Applications look different across
operating systems Why might this be good? Why might this be bad?
In SWT Labs, note the differences between swing & swt. Also, notice the differences between mac & pc.
Inheritance (extends)
java.lang.object is the root of all
classes Every class extends (inherits) a superclass (parent) If you dont designate extends, then you are simply inheriting java.lang.object extends can be chained. Inheriting one class will inherit all non-private members up the hierarchy to java.lang.object Interfaces can also be extended
Code Reuse
The point of allowing inheritance through
an extended class is to support code reuse How is reuse accomplished in the Car() class and the Porche() and Pinto() subclasses example discussed last quarter?
private
no specifier
Y
Y
N
Y Y Y
N
N Y Y
N
N N Y
protected Y public Y
Abstract methods
Interface classes define abstract methods because they only define the signature and allows a class that implements the interface to provide the details.
Question Set 3
1. Is it ok for X2 to extend X1 and redefine
x to be a different type? 2. Except for java.lang.Object, all classes (may/must) have (one/many/one or many) parent class(es) and (may/must) have (one/many/one or many) child classes
Question set 4
1. In the javax.swing library, what is the
relationship between a JApplet and an Applet? 2. Why is java.awt.Component an abstract class? What are some classes that inherit from it (directly and indirectly)? 3. Why are event listeners interface classes instead of regular classes?
Polymorphism
Using the same name to refer to methods
that perform different tasks
Method Overloading Method Overriding
Polymorphic Variables
public void useObject(Object o) In this example, you could pass any type of object into the method The real type is determined at run time by the Java Run-time Environment