The initialization method for classes in Python is __init__ (), therefore, the initialization method of the parent class subclass is this, if the subclass does not implement this function, the initialization function of the parent class is invoked
Java is a single inheritance language, but in the inheritance relationship of subclasses, there are cases where the parent class and the interface have the same method.
Let's take a step-by-step validation:
1. Subclass inherits the parent class,
The subclass and parent class return value parameters are the same, the function name is the same, and the virtual keyword is the type of the object that determines which function is called.
Subclasses and parent classes as long as the function
In the Java programming language, the initialization of objects is very structured, and this is done to ensure security. In the previous module, you saw what happened when a particular object was created. Because of inheritance, objects are
Before you make a mistake, the variable does not have a "rewrite" to say, only the method can be "rewritten". If we declare a variable in the subclass that is the same as the parent class, the actual case is that there are two variables of the same
In Java inheritance, constructor is not inherited, but called (implicitly or explicitly ).
The following is an example:
Public class fatherclass {
Public fatherclass (){System. Out. println (100 );}
Public fatherclass (INT age ){System. Out.
ExtractA subclass cannot inherit an explicitly defined construction method of a parent class, and if you want to inherit the constructor of the parent class, you need to inherit it by overriding the constructor method and calling the constructor of
Put the test code first
name = $value; echo $this->name; }}class B extends A{ public function Name() { $this->setName('abc'); }}$b = new B();$b->Name();
The output is ABC, will the parent class be instantiated
The differences between sub-classes in Java and C ++ on the accessibility reduction covered by parent-Class Functions
Preface
The question "the sub-classes in Java and C ++ have reduced the accessibility of the parent class function coverage" seems
Code parsingSub-class Packagecom;/*** Sub-class *@authorHuage **/ Public classTestextendstest1{ Public Static voidMain (string[] args) {NewTest ();//To test the subclass and parent overload relationships and call relationships }
Always thought the This keyword refers to the caller object, but this time we really understand that this represents the current object, but pointing to the caller object is actually a polymorphic usage, as follows: B inherits A, invokes the Class A
PHP parent class calls subclass method instance. This article will introduce to you the PHP parent class to call subclass method instances. I hope this tutorial will be helpful to you. Today, I suddenly discovered that the subclass method needs to
Read the official PHP manual, but also "concise" ... Attribute definition is also directly Var, this fools is also drunk, alas ...
Here is a post with the code for the test: http://bbs.phpchina.com/thread-116668-1-1.html
Does the inheritance have
There is a super keyword in Java that can call the constructor of the parent class and non-private members. The keywords used in C # are base, but their usage is different.
1. Call the constructor of the parent class
// Parent classPublic class
1 Subclass Call Parent Class construction methodclassAnimal (object):def __init__(self):Print("Init Animal class~") defRun (self):Print("Animal run!")classDog (Animal):def __init__(self):#The Kawai class does not override the constructor method,
The initialization method of a class in Python is __init__ (), so the initialization method of the parent class and subclass is this, and if the subclass does not implement __init__ (), the initialization function of the parent class is called,If
Write while thinking
Explore the subclass object assigned to the parent class object #include using namespace Std;Class A{Public:int A;int b;};Class B:public A{Public:int A;int b;void Func (){A::A = 100;//The control of the inherited part, by the
======= subclasses are instantiated by default when the parent class is empty, the constructor is super (), which can be omitted.However, when the parent class does not have an empty construction method, it must call this method in the subclass to
Features of the JAVA sub-parent class and java features
I. variables (attributes)This indicates the reference of the current object. this variable is first found in this class. If it is not found, it will be found in the parent class.Super is used
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.