ostrich will fly away. Although ostriches can not fly, but other features have "bird" characteristics, so in the declaration of "Ostrich" class is still able to inherit the "Bird" class, but must be in the "ostrich" class in the "Birds" class inherited from the "fly" method to rewrite, you need to overload the
, but you have to override the "Fly" method in the "Ostrich" class in the "Birds" class to overload the methods in the parent class in the subclass.
In the following example, there is a "talking" method in the declared person class, and the student
1. Subclasses after the instance is created, the class initialization method calls the parent class's initialization method (except for the Java.lang.Object class, because the Java.lang.Object class does not have a parent class),
() still accesses the method that is reloaded in the subclass. Example 2 Public Class Parent {public string name = "Tom"; Public void Init () {system. Out. println (this. Name );}} Public class son extends parent {public string name = "Jack"; Public void Init () {super. init (); system. out. println (this. name
1. After a subclass creates an instance, the class initialization method calls the initialization method of the parent class (except for Java. lang. object Class, Because Java. lang. object class does not have a parent
. println ("name:" + getName () + "Age:" + getAge () + "Salary:" + getMoney ());}} public class ABSDemo01 {public static void main (String [] args) {Student s = new Student (10, "James", 100); s. want (); Worker w = new Worker (35, "Ming", 1000); w. want ();}}
Analyze the above Code:
The above code overwrites the constructor public Person (int age, String name) i
*
*/
public class Executetest {
public static void Main (string[] args) {
New subclass instance, assigned to the declared parent class object
Superclass superclass = new subclass ();
Superclass Object Invoke ToString
System.out.println (Superclass.tostring ());
}
}
Printed log: Superclass's tostring----The name of the cl
When watching the video today, Mr. Fang lixun mentioned this problem. He gave an example saying that his father had a wrong method, which could lead to his own mistakes and possibly murder and arson. If the son inherits the father's method, the son must not be worse than the father, and cannot play women on the basis of murder and arson.
After hearing this problem, I felt that something was wrong. Even in the simulated reality, a son cannot be worse than a father. Such a thing is too contrary t
that the function of the proxy object equals the core business logic functionality of the target object plus the shared functionality. The proxy object is transparent to the user, and is the product of the process of running the program.
Weaving (Weaving): The process of applying facets to a target object to create a new proxy object. This process can occur in the compilation period, the class loading period and the operating period, of course, d
already written the pseudo-code:
Reply content:
class A{ public $son_function; public function __construct() { $this->son_function = ? //这里获取到子类的方法名 }}class B extends A{ public function test() { } public function XML() { }}$b = new B();$b->test();echo $b->son_function; //这里应该是test $b->XML();echo $b->son_
the general method "flying" of the bird ". When the "ostrich" class is used as its subclass, the "flying" method will be inherited, but as long as the "flying" method in the "ostrich" class is called, the ostrich will fly away. Although the ostrich does not fly, other features have the "bird" feature. Therefore, when declaring the "ostrich" category, it can still inherit the "bird" category, however, the "
Php implements parent to call the constructor and overwriting methods of the parent class. Php implements the constructor and overwriting methods for parent to call the parent class. This article mainly introduces the constructor
long as the "Flying" method in the "Ostrich" class is called, the ostrich will fly away. Although the ostrich does not fly, other features have the "bird" feature. Therefore, when declaring the "Ostrich" category, it can still inherit the "bird" category, however, the "Flying" method inherited from the "bird" class must be rewritten in the "Ostrich" class, and t
long as the "flying" method in the "ostrich" class is called, the ostrich will fly away. Although the ostrich does not fly, other features have the "bird" feature. Therefore, when declaring the "ostrich" category, it can still inherit the "bird" category, however, the "flying" method inherited from the "bird" class must be rewritten in the "ostrich" class, and t
does not fly, other features have the "bird" feature. Therefore, when declaring the "ostrich" category, it can still inherit the "bird" category, however, the "flying" method inherited from the "bird" class must be rewritten in the "ostrich" class, and the method in the parent class must be reloaded in the subclass.
I
reference a class rather than an object method, you can use: (two colons) instead of->.
Therefore, parent ::__ construct () indicates that the _ construct () method of the parent class is called.
Modify the code in the previous article "use
, the "Flying" method inherited from the "bird" class must be rewritten in the "Ostrich" class, and the method in the parent class must be reloaded in the subclass.
In the following example, the declared person class has a "speaking" method. After the student
This article mainly introduces the constructor and overwriting methods for php to implement parent to call the parent class. Based on the previous article about using class inheritance to solve code duplication problems, it further analyzes the constructor and
This article m
Brief introduction
For the Combox function to minimize the JS code, the page prototype reference Dojo Combox appearance, support keyboard action and automatic screening, highlighting and so on
Api
Initialization method
Encoding method
var c=new combox (document.getElementById (' a '));
Or
var c=new combox (document.getElementById (' a '), {debug:true});
CSS Declaration mode
As long as the
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.