Summary of the abstract class of Java learning

Source: Internet
Author: User
Tags define abstract

Features of abstract classes:
1, the method is an abstract method only if the declaration is not implemented, it needs to be abstracted, the abstract method must be defined in the abstract class, and the class must also be abstract.
2, abstract classes cannot be instantiated. Why? Because it doesn't make sense to invoke an abstract method.
3, an abstract class must have its subclasses covered by all the abstract methods, the subclass can be instantiated, otherwise, the subclass is an abstract class.

4, is there a constructor in the abstract class?
There, used to initialize the subclass object.

5, can abstract classes not define abstract methods?
OK. However, it is rare to have the class create an object. The object of the AWT adapter is this class, usually the method in this class has the method body, but there is no content.

Abstract class Demo
{
void Show1 ()
{}

void Show2 ()
{}

3, abstract keywords can not coexist with those keywords?
Private, No.
Static No.
Final No.

4, the similarities and differences between abstract class and general class.
Same point:
Both abstract and generic classes are used to describe things, and members are set internally.
Different:
1, the general class has enough information to describe things.
Abstract classes may not have enough information to describe things.
2, abstract methods cannot be defined in general classes, only non-abstract methods can be determined.
Abstract methods can be defined in abstract classes, and non-abstract methods can also be defined.
3, the generic class can be instantiated.
Abstract classes cannot be instantiated.

5, the abstract class must be a parent class?
Yes. You can instantiate a child class only if it needs to overwrite its method.

Summary of the abstract class of Java learning

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.