abstract abstract
Abstract class : a class modified by abstract
Abstract method : the method modified by abstract
No method body; (must exist in an abstract class)
Requirements : Define the work content of different positions in the development department
Development department Develop --> work()
java siege lion: work–> back-end development
Web programmer: work–> front-end development
Note :
1. Abstract classes cannot be instantiated
2. The abstract method must exist in the abstract class
3. The abstract class can define or not define abstract methods, and can define any content
4. The use of abstract classes:
1) Concrete subclass objects call members
Override all abstract methods + add as needed
2) Partial rewriting of abstract subclasses
Rewrite on demand + add on demand
5. Abstract methods must be rewritten, but only need to be rewritten once, and rewritten as many times as needed
6.abstract cannot be used with private, final, static, native
public class Class001_Abstract { public static void main(String[] args) { //Abstract classes cannot be instantiated //Develop d = new Develop();
//Concrete subclass object
Java java = new Java();
java.sleep();
java.work();
java.test();
java.insert();
}
}
//Parent class
abstract class Develop{ //I don't know how to write the work method body, I don't know what to write—> public abstract void work(); public abstract void sleep();
public void test(){ System.out.println("abstract method's test"); } }
//Concrete subclass
class Java extends Develop{
@Override
public void work() { System.out.println("Backend Development"); }
@Override
public void sleep() { System.out.println("Sleep while typing code... "); }
//Add
public void insert(){ System.out.println("New method in java"); } }
//abstract subclass
abstract class Web extends Develop{
@Override
public void work() { System.out.println("Front-end development"); }
//Add
public void webInsert(){ System.out.println("web added"); } }