The relationship between the Java abstract class and the abstract method

Source: Internet
Author: User

The relationship between abstract classes and abstract methods
Classes with abstract methods must be abstract classes; Abstract classes do not necessarily have abstract methods
When subclasses inherit abstract classes, they must all implement (or override) the abstract methods in the abstract class, otherwise the subclasses are still abstract classes
Because subclasses inherit the entire contents of the parent class, it is also equivalent to an abstract method in the subclass, which overrides the abstract method.

Abstract class features: Must have the abstract keyword decoration, can not be created by new object, abstract method can not write function body (non-abstract method must write function body)

Keyword Small summary: Do not want other classes to override the method, with final, content uncertainty method, with abstract (sub-class usage is not the same);
Want to share with static

1 //define an abstract class2 Abstract classstudent{3     //Abstract Methods4      Public Abstract voidstudy ();5     //Non-abstract methods6      Public voidWork () {7SYSTEM.OUT.PRINTLN ("Study hard");8     }9 }Ten classGoodstudentextendsstudent{ One     //the abstract method must be implemented, otherwise the class is still an abstract class A      Public voidStudy () { -SYSTEM.OUT.PRINTLN ("Good students do not study"); -     } the } -  Public classTest { -      Public Static voidMain (string[] args) { -Goodstudent s=Newgoodstudent (); +         //calling the implementation method - s.study (); +         //invoke a non-abstract method inherited from an abstract class A s.work (); at     } -}

The relationship between the Java abstract class and the abstract method

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.