Inner Class

February 5, 2006

Inner Classes may nested or not.

Because the inner class constructor must attach to a reference of the enclosing class object, things are slightly complicated when you inherit from an inner class.

public class InheritedFromInner extends Outer.Inner{ .. }

Nested Class

February 5, 2006

If you don’t need to connect outer class object and inner class object, you can make inner class static.
Nested Class: define a class within another class, and the nested class can be static or not.

Static Nested Class:

1. You don’t need object of outer class in order to create an object of an inner class.
2. You cannot access non-static outer class object from the object of an inner class.
3. Roughly, it like nested class in C++ except it can access the private outer class member in java.

Interface

February 5, 2006

An interface definition begin with the keyword interface and contains a set of public abstract methods. Interface class may also contains public static final data. To use an interface, you can create the class implement the interface, and the calss must define every method in the interface with the same number of argument and return type specified in the interface definition (overridden).

Abstract Superclass

February 4, 2006

There is no object of Abstract class because it is abstract. For example, the class of Animal can be a abstract superclass, which means there is at least one abstract method (function) in the Animal class.

abstract class Animal{
private int itsAge;
public int getAge() {
return itsAge;
}
public abstract void move(); //abstract function
}

Because Animal is abstract class, you cannot do this:

Animal a = new Animal (); //Animal is abstract; cannot be instantiated
In the other word, object can only exist when the class is conrete class. You can derived the Cat class from Animal Class, and implement the move method, then you can do this:

Animal a = new Cat (); //object of Cat is also the object of Animal;