JAVA Abstract class, java Abstract class

Source: Internet
Author: User

JAVA Abstract class, java Abstract class

Abstract class
Abstract is a modifier
Can be modified, can be modified class
1. When multiple classes have the same functions, but the feature subjects are different, we extract them upwards. Only the feature definitions are extracted.

Abstract class features:
1. abstract methods must be in abstract classes.
2. abstract classes and abstract methods must be modified by abstract keywords.
3. abstract classes cannot be created because it is meaningless to call abstract methods.
4. To use methods in an abstract class, the subclass must overwrite the methods in the abstract class, and then create a subclass object to call
5. Non-abstract methods can be defined in abstract classes. Sometimes we need to convert this class into abstract classes when the object cannot be created by the new keyword.
6. If the subclass only overrides a part of the abstract method, the subclass is still an abstract class. If the abstract class method is to be used, the subclass must override all methods in the abstract class.

It is worth noting that abstract classes are not very different from common classes.
1. An abstract class cannot use the new keyword to create an object.
2. abstract classes can contain abstract methods.

Abstract class Animal {// if the method is abstract, the class must also be abstract. The class must be abstract. The class is abstract, and the method can not abstract void sing (); // abstract method. Remove the braces and use the abstract keyword to modify} class Cat extends Animal {void sing () {System. out. println ("");} class Dog extends Animal {void sing () {System. out. println ("Wang sing") ;}} public class Test {public static void main (String [] args) {Animal c = new Cat (); c. sing ();}}

 

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.