The following is a java4android video tutorial from marschen.
Why use abstract classes for 24th Sets
Main content.
Abstract classes express a concept.
// If a piece of code is incorrect in semantics, it should also be incorrect in syntax. this is a point that modern programming theory emphasizes, but there is no such language completely real // abstract class printer {void open () {system. out. println ("open");} void close () {system. out. println ("close");} void print () {}// abstract void print (); // The abstract function // has an error in semantics, let's make it syntactic incorrect. // syntax errors are easier to check .}
// This printer prints class hpprinter extends printer {void print () {system. Out. println ("Print with ink jet printer ");}}
// This printer is a dot matrix printer class canonprinter extends printer {void print () {system. Out. println ("Print with dot matrix printer ");}}
Class test {public static void main (string ARGs []) {printer p1 = new hpprinter (); // transforms upwards. The subclass object is assigned to the reference of the parent class. p1.open (); p1.print (); p1.close (); printer P2 = new canonprinter (); // transforms upwards. The subclass object is assigned to the reference of the parent class. p2.open (); p2.print (); p2.close ();}}
Why use abstract classes,
For example, if you do not use an abstract class,
Subclass may forget to implement the print () method of the parent class.
The error will be hidden.