package test9;
/*
* 1. How to define abstract classes?
* Add abstract before the class keyword
* 2. Abstract classes cannot be instantiated, that is, objects cannot be created
* 3. Although abstract classes cannot be instantiated, abstract classes also have a construction method, which is used to create objects for subclasses Yes , inheritance and polymorphism are generally used
* 4. Abstract classes can define abstract methods:
* Syntax of abstract methods: Add the abstract keyword to the modifier list of the method, and the abstract method should end with ; instead of {}
* For example, public abstract m1();
* 5. If a non-abstract class inherits an abstract class, the method in the abstract class must be overridden and changed to a non-abstract method because the abstract method must appear in the abstract class
* /
public class test9 {
public static void main(String[] args) {
a a1=new b();//Polymorphism, creating an object of a supertype to point to a subtype
}
}
abstract class a{
a(){ //Abstract class There may or may not be abstract methods in the class, but the abstract methods must appear in the abstract class
System.out.println("a````");
} }
class b extends a{
b(){//The construction method does not necessarily call the object, you can use super to call
System.out.println("b````");
}
}
/*
* 1. How to define abstract classes?
* Add abstract before the class keyword
* 2. Abstract classes cannot be instantiated, that is, objects cannot be created
* 3. Although abstract classes cannot be instantiated, abstract classes also have a construction method, which is used to create objects for subclasses Yes , inheritance and polymorphism are generally used
* 4. Abstract classes can define abstract methods:
* Syntax of abstract methods: Add the abstract keyword to the modifier list of the method, and the abstract method should end with ; instead of {}
* For example, public abstract m1();
* 5. If a non-abstract class inherits an abstract class, the method in the abstract class must be overridden and changed to a non-abstract method because the abstract method must appear in the abstract class
* /
public class test9 {
public static void main(String[] args) {
a a1=new b();//Polymorphism, creating an object of a supertype to point to a subtype
}
}
abstract class a{
a(){ //Abstract class There may or may not be abstract methods in the class, but the abstract methods must appear in the abstract class
System.out.println("a````");
} }
class b extends a{
b(){//The construction method does not necessarily call the object, you can use super to call
System.out.println("b````");
}
}