java--Object-oriented advanced

Source: Internet
Author: User
Tags define abstract

Abstract class

Abstract class: A class that is unclear

Abstract method: A method that is not clear

Methods feature declarations are the same, but methods have different functional bodies. 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.

define the format:

Classes that define abstract functions must also be decorated with the abstract keyword, and the class that is decorated by the abstract keyword is an abstract class.

/*    abstract class, cannot instantiate object, cannot    create object for the reason:  if you really get new, object. Call abstract method, abstract method without a body, simply cannot run *    inheriting his subclass must override the defined abstract method */ Public abstract class Develop {     //abstract type public    -abstract void work ();    Abstract method}
Features:

1. Abstract classes and abstract methods need to be modified by abstractions. Abstract methods must be defined in an abstract class.

2. Abstract classes cannot create objects directly, because there is no point in invoking an abstract method.

3, only after overriding all abstract methods in the abstract class can the subclass create the object. Otherwise, the subclass is an abstract class.

The reason for inheriting abstract classes, more in mind, is to be more simple in the face of generic type operations.

Questions:

1, abstract class must be a parent class?

Yes, because of the constant extraction.

2 . Can there be no abstract method in an abstract class? If so, does it make sense to define the class as an abstract class? Why?

There can be no abstract method, it makes sense, and does not let others directly create the class object.

3. Abstract keywords can not and which keywords to coexist?

    • 1,Private: The method subclass is not inheritable, and there is no overwrite, and abstract and private use the modified method,abstract subclass to implement this method, and the private modifier subclass simply cannot get the parent class method. Contradict each other.
    • 2.final,
    • 3,static,

java--Object-oriented advanced

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.