When certain methods of the parent class are not deterministic, the abstract keyword can be used to decorate the method [abstraction], and abstract to decorate the class [abstract class].
We all know that the parent class is to extract the properties and methods that the subclass has in common, some of which have already been explicitly implemented, some of which cannot be determined, then we can define them as abstractions and reuse them in the later days to materialize. In this way, the abstract class is born.
For example, the "animal" parent class is defined, where the "animal name" and "Animal age" properties have been clarified, but the "animal called" method is not clear, and "animal call" can be defined as an abstract method.
Therefore, abstract classes are designed to extract the same but indeterminate things for later reuse. The purpose of defining abstract classes is to implement abstract classes in subclasses.
Package Javastudy;public class AbstractDemo1 {public static void Main (string[] args) { //TODO auto-generated met Hod stub }}//This is an abstract class of abstraction classes Animal { String name; int age; Animals will be called public abstract void Cry ();//Not sure how animals are called. Defined as an abstract method to resolve the uncertainty of the parent class method. Abstract methods cannot be implemented in the parent class, so there is no body of the function. However, in subsequent inheritance, this method is implemented specifically. }//abstract classes can be inherited//When the inherited parent class is an abstract class, all the abstract methods in the abstract class need to be fully implemented. Class Cat extends Animal { //Implements Cry abstract method of the parent class public void Cry () { System.out.println ("cat called:");} }
The class that is modified with abstract, that is, abstract, is modified by the abstract method, that is, abstraction. An abstract method cannot have a method body, inheriting an abstract parent class from a subclass, overriding the abstract method of the parent class.
Abstract class can not be instantiated, because the method in the abstract class is not materialized, is an incomplete class, the direct instantiation of no meaning.
Abstract classes do not necessarily contain abstract methods, and abstract classes can have no abstract methods.
Once the class contains the abstract method, the change class must be an abstract class.
Java abstract class and abstract method (abstract)