Java can also create a class that is specifically used as a parent class, which is called an abstract class. Abstract classes function somewhat like "templates", which are designed to modify and create new classes based on their format. However, it is not possible to create an object directly from an abstract class, but to derive a new class from an abstract class and then create the object.
Abstract class definition rules:
1. Abstract classes and abstract methods must be modified with the abstract keyword.
2, abstract class can not be instantiated, that is, you can not use the new keyword to produce objects.
3. Abstract methods can only be declared, but not implemented.
4. A class containing an abstract method must be declared as an abstract class, and the subclass of the abstract class must replicate all the abstract methods before it can be instantiated, or the subclass is an abstract class.
Declares abstract class person{ String name; int age; String occupation; Declares an abstract method public abstract String Talk ();} Class Student extends person{public Student (string name, Int. age, String Occupation) { this.name = name;
this.age = age; this.occupation = occupation; } Replication Talk () method public String Talk () { return "Student---> Name:" +this.name+ ", Age:" +this.age+ ", Occupation:" + this.occupation;} } Class testabstractdemo1{public static void Main (String args[]) { Student s = new Student ("Zhang San", 20, "student"); System.out.println (S.talk ());} }
Java abstract classes, literacy stickers