|
Needless to say, is not an instance of an abstract class, abstract class not specifically described as a specific type of thing, it is the common feature extraction similarity specific things abstract, realize it does not make any sense.
If you do not inherit the abstract class, but "instance" of abstract class, written as follows:
package subClass;
abstract class ParentClass {
public abstract void abstractFun ();
}
class SubClass {
// Here "instantiated" ParentClass is instantiated ParentClass () {}, and abstract methods ParentClass implementation, therefore an abstract class is not instantiated
ParentClass parentClass = new ParentClass () {
@Override
public void abstractFun () {
System.out.println ( "abstractFun ()");
}
};
}
public class TestExtends {
public static void main (String args []) {
SubClass sub = new SubClass ();
sub.parentClass.abstractFun ();
}
}
Examples of "ParentClass is new ParentClass () {}, and to achieve ParentClass abstract method, rather than newParentClass ().
The above structure and Android similar event listeners:
findViewById (R.id.stop_Button) .setOnClickListener (new View.OnClickListener () {
When @Override omitted @Override do not think that is an internal class.
public void onClick (View v) {
stopService (it);
}
}); |
|
|
|