PHP abstract method and abstract class Abstracts keyword
The abstract keyword is used to define abstraction methods and abstract classes.
Abstract methods
Abstract methods are methods that do not have a method body, specificall
When certain methods of the parent class are not deterministic, the abstract keyword can be used to decorate the method [abstraction], and abstract to decorate the class [abstract class].We all know that the parent class is to extract the properties and methods that the subclass has in common, some of which have already been explicitly implemented, some of which
An abstract method is a method without a method body. as long as a method in a class is an abstract method, this class must be defined as an abstract class, if you are not familiar with it, you can look at PHP abstract methods and abstract keywords in
Introduction and Application of abstract keywords in PHP abstract methods and abstract classes
PHP abstract methods and abstract keywords
Abstract keywords are used to define abstract
An abstract method is a method without a method body. as long as a method in a class is an abstract method, this class must be defined as an abstract class, if you are not familiar with it, you can look at PHP abstract methods and abstract keywords in
.htmlAbstraction classes: Abstract classAbstract method: Public abstract void Search ();Class must be an abstract class as long as there is an abstract method, the abstract method simply declares that there is no method body, an abstract
Today, teacher Liang fangming explained the importance of abstract thinking, the role of abstract classes, the role of interfaces, and the role of abstract classes and interfaces. Next, I will review what I learned today. If there are any mistakes or shortcomings, please point out them.
First, let's start with an example. The implementation process of the bubble
1. Abstract classes can not be instantiated , no , One or more abstract methods2. Abstract methods only declarations of methods but no implementations of methods , classes with abstract methods must be declared as abstract classes , Subclasses must override all the
In the previous article, we used the simplest method to implement the bubble sort method. It is now implemented using the abstract class method.
Abstract classes Implement Bubble Sorting:
First, define an abstract class. The function of this abstract class is to implement the Bubble sorting method. The code is:
Using
Abstract METHODS in abstract classes cannot be final, but they can be compiled by adding final before non-Abstract METHODS because abstract and final are mutually exclusive. The former is used for inheritance, and the latter is not allowed for inheritance.
Abstract METHODS
The problem that this paper solves
What is abstract class
Application Scenarios for abstract classes
Can interfaces be implemented in a method?
The difference between an interface and an abstract class
1 What is abstract classWhen declaring a keyword abstr
Abstract method: A method that does not have a method body in a class is an abstract method.Abstract classes: Classes that contain abstract methods are called abstract classes.||||||||| Abstract classes cannot be instantiated (new)Why use
(such as the Java Interpreter) runs a method, it first finds the method in the current class, then finds it in its superclass, and always looks up at the class level until the method is foundExamples of final methods:Class parent{public Parent () { }//constructor method final int getpi () {return math.pi;}//Finalization method}Description: GETPI () is a finalization method declared with the final modifier and cannot be overloaded in subclasses2. Abstr
This article mainly introduces the problem analysis of abstract and abstract methods in PHP, and some friends need to refer to it. In an object-oriented (OOP) language, a class can have one or more subclasses, and each class has at least one interface that the public method accesses as external code. and abstract methods are introduced to facilitate inheritance
The relationship between abstract classes and abstract methodsClasses with abstract methods must be abstract classes; Abstract classes do not necessarily have abstract methodsWhen subclasses inherit
Object-oriented programs are constructed by hierarchical structure of classes. In a single inheritance language such as PHP, the inheritance of a class is tree-like. A root class has one or more subclasses, and then inherits one or more next-level subclasses from each subclass. Of course, there may be multiple root classes that can be used to implement different functions. In a well-designed system, each root class should have a useful interface that can be used by the application code. If our a
we conclude that the employee class should not be instantiated.
How do I ensure that a class is not instantiated? Just declare the class as an abstract class. You can use the abstract keyword as follows:
Public abstract class Employee {
private String name;
private double salary;
TBC
}
When an employee class is declared
Abstract class and abstract methods are decorated.A class that contains an abstract method can only be defined as an abstract class, but there is no abstract method in an abstract class.There is no method body for
Features of the Java abstract class:* Abstract classes cannot be instantiated* Subclass inherits Abstract class and instantiates subclass* Subclasses inherit abstract classes has penny must implement abstract methods in abstract c
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.