Java programming Idea--abstract class

Source: Internet
Author: User

First, abstract class

1. What is abstract class

For a method of a class, you can describe one of these attributes. such as the animal's running, but different objects may not be the same way.

This requires an abstraction of the method. This allows for inheritance based on the characteristics of different classes, and then overrides the abstract method.


Abstract class * *

{

abstract void * * ();

}


2, the characteristics of abstract class

(1) Abstract classes can not be instantiated

(2) Abstract methods of abstract classes are simply declared and not implemented. Method is described by the keyword abstract. Abstract methods corresponding to the abstract class, also to be described by the abstract keyword.

(3) After being inherited in an abstract class, all of the abstract methods must be implemented. Otherwise, it is an abstract class and cannot be instantiated.


3. Some problems of abstract class

(1) Abstract class has no constructors

An abstract class has a constructor function. Abstract classes will have subclasses, and constructors in abstract classes can initialize subclasses.


(2) Abstract methods can not be defined in abstract classes?

OK!

Rarely, the purpose is not to let it create objects.


(3) What keywords cannot be used to coexist with abstract keywords?

Private cannot be, because abstract methods are overwritten, and private methods cannot be overwritten.

Static can not

Final cannot be


(4) Similarities and differences between abstract classes and general classes?

Same: Both describe the class's

Different: abstract class only declaration, no specific description.

Abstract methods cannot be defined in a generic class, and abstract methods can be defined in an abstract class.


(5) Abstract class must be a parent class?

Yes! Subclasses need to overwrite their methods in order to instantiate!












Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java programming Idea--abstract class

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.