Introduction to the abstract class of Java basics

Source: Internet
Author: User
Tags modifier

Abstract class Features: 1. When a method is declared without a specific implementation, it needs to be decorated with the abstract modifier.     Abstract methods must be defined in abstract classes, so abstract classes also need to be decorated with an abstract 2. Abstract classes can not be instantiated, why? Because calling an abstract method doesn't make sense 3. Subclasses of an abstract class must overwrite all of the parent class's abstract methods before the subclass can be instantiated, or the subclass is abstract; class A extends Chouxiang {     @Override      void bark () {///Only the bark () method is overridden to instantiate Class A           // TODO auto-generated Method StubSystem. out. println ("What do you mean?");     }} Public Abstract class Chouxiang {      Abstract void bark ();//must have subclasses rewritten to make sense      Private int Bark ( int a, int b There can be non-abstract methods in the {///abstract class, that is, you do not need the subclass to override the method             return a + b;     }      Public Static void Main (string[] args) {A a = New A ();           a. Bark ();//The Overridden bark () method is called     }} 
    • Are there constructors in abstract classes?
there are, for the initialization of a subclass
    • Can there be no abstract method in an abstract class?
Yes, but it's rare to keep subclasses from creating objects
    • Abstract classes are not available and which keywords to use
1.private: Private decorated methods in the parent class are not visible to subclasses, that is, subclasses cannot overwrite methods 2.static: When using the static modifier, you can call the method directly using the class name, so that the subclass does not have to be implemented;     Even calling directly is just a method declaration, and it doesn't make sense. The meaning of 3.final:abstract is to allow subclasses to overwrite the modified method, but final is not allowed to overwrite the method, the contradiction between the two
    • The Star class must be a parent class.
Yes, because it makes sense to need its subclasses to cover its methods.

Introduction to the abstract class of Java basics

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.