Abstract classes and interfaces

Source: Internet
Author: User

That is, there is no specific instance object class. Abstract classes are similar to "templates" to create and modify new classes based on their formats. Objects cannot be directly created by abstract classes. They can only be derived from abstract classes to create objects. When a class is declared as an abstract class, a modifier must be added before the class.
The member methods in the abstract class can include general methods and abstract methods. When a method is an abstract method, it means this method. Otherwise, the method of its subclass is still
Abstract classes do not have actual functions and can only be used to derive their subclasses. Abstract classes can contain constructor methods, but they cannot be declared as abstract.
Call methods in abstract classes

 
Summary: classes and methods.

Abstract Class AA System. out. println ("can" AbstractClass System. out. println ("override abstract method" System. out. println ("I am the AA method of the aa interface "}

Interface

The interface is also a type of abstract class, and the slot we see is based on

The interface only defines the specifications that the class should follow, but does not care about the internal implementation of the class. The interface only specifies the methods required for this class, thus implementing it.

Interface features:

 

A a =. a (); Integer number = 15; StringBuffer sb = StringBuffer ("ad"); a (); B (); C D System. out. println ("override Interface C abstract method" System. out. println ("override the abstract method of interface B" System. out. println ("overwriting the abstract method of interface "}

 

Summary

An abstract class can only use an inheritance relationship once. However, a class can implement multiple interfaces.

The abstract can have its own data members or non-abstract member methods.





.



Conclusion
  

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.