An overview of abstract classes in the Java language

Source: Internet
Author: User
Tags define abstract

Abstract class

Characteristics:

1, the method is abstract and needs to be modified only if the declaration is not implemented.

Abstract methods must be defined in an abstract class. The class must also be modified by the abstract.

2, abstract classes cannot be instantiated. Because invoking an abstract method is meaningless.

3, an abstract class must have its subclasses overriding all the abstract methods that can be instantiated. Otherwise, this subclass is an abstract class.

1, do abstract classes have constructors?

There, used to initialize the subclass object.

2, can abstract classes not define abstract methods?

OK. But it's rare. The purpose is to not allow the class to create objects. The adapter object for AWT is this class.

Usually the method in this class has a method body, but there is no content.

3, abstract keywords can not coexist with those keywords?

Private is not possible because abstract class subclasses cannot be overwritten. Privateabstract an illegal modifier combination.

Static is not possible, because static can invoke methods without objects, with no meaning. Static abstract an illegal modifier combination

Final is not possible because the final modified method cannot be overridden, but the abstract requirement is overwritten, conflicting.

4, the similarities and differences between abstract class and general class.

The same point: abstract and generic classes are used to describe things, and members are defined internally.

Different points:

1) The general class has enough information to describe the transaction.

Abstract classes describe transactions that may be insufficient information.

2) Abstract methods cannot be defined in a generic class.

Abstract methods can be defined in abstract classes, and non-abstract methods can also be defined.

3) A generic class can be instantiated.

Abstract classes cannot be instantiated.

5, abstract class must be a parent class?

Yes, you can instantiate a child class only if it needs to overwrite its method.

An overview of abstract classes in the Java language

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.