Abstract classes in java and java

Source: Internet
Author: User
Tags define abstract

Abstract classes in java and java

Abstract class

Features:

1. When a method is declared to be unimplemented, the method is an abstract method and needs to be abstract modified.

Abstract methods must be defined in abstract classes. This class must also be abstract.

2. abstract classes cannot be instantiated. It is meaningless to call the abstract method.

3. the abstract class must have its subclass covering all abstract methods before it can be instantiated. Otherwise, this subclass is still an abstract class.

 

1. Do abstract classes have Constructors?

Yes. It is used to initialize the subclass object.

2. can abstract classes not define abstract methods?

Yes. But it is rare. The purpose is not to allow this class to create objects. AWT adapter objects are of this type.

Methods In this class usually have method bodies, but there is no content.

3. Cannot abstract keywords coexist with those keywords?

Private does not work, because the subclass of the abstract class cannot be overwritten. The combination of modifier privateabstract is invalid.

Static does not work, because static does not need to call methods of objects and does not make sense. Combination of modifier invalid static abstract

Final does not work because the final modification method cannot be overwritten, but the abstract requirement is overwritten and conflicted.

4. Similarities and Differences between abstract classes and general classes.

Similarities: abstract classes and general classes are used to describe things, and members are defined internally.

Differences:

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

Abstract classes may be insufficient to describe the transaction information.

2) abstract methods cannot be defined in general classes.

Abstract classes can define abstract methods and non-abstract methods.

3) general classes can be instantiated.

Abstract classes cannot be instantiated.

 

5. Must an abstract class be a parent class?

Yes, because the subclass can be instantiated only after the subclass overwrites its method.

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.