9. Abstract classes and abstract functions

Source: Internet
Author: User

1. Abstract function syntax features (natural to be used as Father's) definition: only function definition, no function body function (no entity). cannot be initialized. Abstractvoid Fun (); classes defined with abstract are used as abstract classes
Characteristics: 1.Abstract classes cannot be used to create objects of new type, and are inherently inherited;subclasses inherit abstract classes, and then replicate abstract functions so that the class is not an abstract function. To generate child class objects. 2.If a class contains abstract functions, then the class must be declared as abstract class; 3.If there is no abstract function in a class, the class can also be declared abstract so that the object is not generated by others.   In the future, it is used to write programs, and abstract is also called the base class for inheritance.     2. Abstract classes can have constructors? Condition: Abstract classes do not actually generate objects, but because of inheritance, subclasses can generatethere are constructors that invoke the constructor of the abstract class when generating the subclass object. Abstract classes must be extend. object is not an abstract class in full sense, because it does not have a method that must be overridden.
3. The role of abstract classesNote: If a piece of code is semantically wrong, there should be a syntax error, and grammatical errors are easier to find than semantic errors. For example, if a parent class is not an abstract class, it is possible for a subclass to forget the replication of some functions of the parent class and not be easily discoverable.if a class, a function we cannot determine. Must be implemented with subclasses and cannot be generalized, the function is defined as an abstract function, and the class is defined as an abstract class.



From for notes (Wiz)

9. Abstract classes and abstract functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.