java--Abstract class

Source: Internet
Author: User

I. Abstract overview

    When we analyze things, we find common content, and then we extract them upwards. There is a special case where the method function declaration is the same, but the method function body is different.

Then it can be extracted, but only the method declaration is extracted, and the method body is not extracted. Then this method is an abstract method.

Second, the characteristics of abstract class

    Abstract methods can only be used in abstract classes

abstract classes and abstract methods must be modified by an abstract

Abstract classes cannot create objects (cannot be instantiated)

There can be non-abstract methods in abstract classes

The relationships of abstract classes and classes are also inherited

A class inherits an abstract class or overrides all abstract methods, or he is an abstract class.

Iii. characteristics of abstract class members

    Member variables

can have member variables

can have constants

Member Methods

There can be abstract methods

can have non-abstract methods

Construction method

You can have a constructor method, and you need to initialize the member variables of the abstract class.

Case:

    Abstract class animal{

public abstract void Eat ();

}

Class Dog extends animal{

overriding abstract methods of abstract classes

public void Eat () {

System.out.println ("Dog chew Bones");

}

}

java--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.