Home > Java > javaTutorial > body text

Abstract classes and interfaces

巴扎黑
Release: 2017-06-26 11:25:31
Original
1249 people have browsed it

Abstract class
Concept: Class modified by the abstract keyword
Member characteristics:
Constructor method: yes
Member variables: no limit, both constants and variables
Members Method: No limit, it can be abstract or not
Relationship with class: Inheritance relationship
Subclass of abstract class: It can be abstract or concrete (all abstract methods must be implemented )
Tips: If there are abstract methods in a class, then the current class must be defined as an abstract class
  A subclass of the abstract class:
    Either implement all abstract methods and call it a normal class
   Or continue to abstract
  Abstract classes cannot be instantiated directly ---->>The only difference between abstract classes and ordinary classes is that they cannot create instance objects and allow abstract methods
  You can use polymorphism Instantiation is instantiated by its normal subclass
Interface
Concept: Java provides the standard interface
Definition format: permission modifier interface interface name {}
Member characteristics:
Construction method: No
   Member variables: can only be constants, the default modifier is public static final
   Member methods: can only be abstract methods. The default modifier of the method is public abstract
Relationship with the class: implementation relationship, multiple implementations can be implemented in a single way, or multiple implementations
Implementation class of the interface: either implements all abstract methods and is called a normal class, or declares it as abstract Class
Implementation of interface: Interface cannot be instantiated directly, and objects can be created by its instantiated classes in a polymorphic manner
There is an inheritance relationship between interfaces, which can be single or multiple inheritance

The above is the detailed content of Abstract classes and interfaces. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!