Python: super
Getting started with super ()
In class inheritance, If you redefine a method, this method will overwrite the method of the same name as the parent class, but sometimes we want to implement the function of the parent class at the same time, we need to call the method of the parent class, which can be implemented by using super, for example:
Class Ani
------Super keyword------Super Purpose: Access superclass "hidden member variables (whether static or not) and static methods" and "overridden instance methods" in subclasses. The superclass here must be a "direct superclass", the most recent superclass above the subclass.How to use Super:① calls the constructor of the superclass in the subclass construction meth
1. Subclass constructors If you want to refer to super, you must put super in the first place of the function. class Base {base () {System.out.println ("base"); }} public class Checket extends Base {checket () {super ();//Call the constructor of the parent class, be sure to place the first statement of the method System.out.println ("Che Cket "); } public s
1. Constructor of subclass if you want to refer to super, you must put super at the top of the function
Copy Code code as follows:
Class Base {
Base () {
System.out.println ("Base");
}
}
public class Checket extends Base {
Checket () {
Super ();//Call the Parent class construction method, be sure to place the first statement
.The non-parametric null constructor that the system automatically adds in the parent class is explicitly written out (in order to have the output, add println):[Java]View Plaincopy
Class base{
Base () {
System.out.println ("base constructor");
}
}
Class derived extends base{
public static void Main (string[] args) {
Derived d=new derived ();
}
}
Output: base constructor, code compiled. From the example, it seems that subclasses can inherit t
First, this usageConcept: This is an object of its own, representing the object itself, which can be understood as: A pointer to the object itself.The usage of this can be roughly divided into three types in Java: 1. Direct reference to ordinary objects: this corresponds to the current object itself.2. Use this to distinguish between members whose names are duplicate. classPerson {Private intAge = 10; PublicPerson () {System.out.println ("Age of Initialization:" +Age );} Public intGetage (int
use super in the JAVA class to refer to the composition of the parent class, using this to refer to the current object. If a class inherits from another class, we will have a parent class object in the subclass object when we new the instance object of the subclass. How do you refer to the parent object inside? Using Super to refer to, this refers to a reference to the current object, and
I recently encountered some questions about super when I was studying java. At first I saw that super had no idea. I found some information and studied it:
In Java, sometimes the member variables or methods in the subclass have the same name as the member variables or methods in the parent class. Because the member variables or method names in the subclass have a high priority, the member variables or metho
This article summarizes the usage of super keywords in Java.
There is a reference to the parent class object mentioned in the book. (I have a bit doubt about this statement. If it indicates the reference of the parent class object, it should be said as follows: System. out. println (super); can output the representation of the parent class object.
However, the above sentence output is incorrect, while Syste
amount of code is large, such a modification could be catastrophic.
So, since Python 2.2, Python has added a keyword super to solve this problem. The following is an official document description of Python 2.3:Copy the Code code as follows:
Super (type[, Object-or-type])
Return the superclass of type. If The second argument is omitted the Super objectReturned
one, in Java, there are usually two ways to use the Super keyword:1. In the subclass of the constructor (initialization), the main call is the default constructor of the parent class, if the parent class has more than one construction method, you can specify a specific constructor by super, such as Super (paras);2. Use a subclass to invoke a hidden or overridden
A super user is the owner of the highest permissions of the system and the only winner of system management. a super user has super permissions and is omnipotent. if the super user is not good at management, it will pose a threat to system security. In addition to avoiding the direct use of
Getting Started with super ()In the inheritance of a class, if you redefine a method that overrides a method of the same name in the parent class, but sometimes we want to be able to implement the function of the parent class at the same time, we need to invoke the parent class's method, which can be achieved by using super, such as:class Animal(object): def __init__(self, name): self.name = name
Reference Design for High-resolution camera cell phone LED flashlight super capacitor
[Date:]
Source: Today's electronics/21IC Author: Advanced Analogic Technologies Company Thomas Delurio
[Font:Large Medium Small]
Mobile phones are becoming the ultimate consumer electronics platform. Its performance includes capturing high-quality images, Wi-Fi network access, crisp audio, longer call times, and longer battery life. However, a
1. Python inheritance and invoking the parent class memberThe Python subclass calls the parent class member in 2 ways, namely the normal method and the Super methodSuppose base is a base classclass Base (object): def __init__ (self): Print "Base Init"The common method is as followsclass Leaf (Base): def __init__ (self): Base. __init__ (self) Print "Leaf Init"The S
Jane's going to talk Super VLAN-conserving IP address isolation two layer communication VLAN aggregation in the implementation of the different Sub-vlan to share a subnet segment address, but also brought Sub-vlan between the three-layer forwarding problem. Want to do the DHCP server must do in the Super-vlan up[Huawei]vlan Batch 2 to 4 100[Huawei]vlan 100[Huawei-vlan100]aggregate-vlan//Configure the curren
Some people may think that why is there a super function in Python that can directly call the parent class method through the parent class name? In fact, many people have misunderstandings about the super function in Python, this article introduces the correct understanding and usage of the super function in Python programming. when the subclass needs to call the
This article mainly introduces the differences between super () and _ init _ () in the python class. This article is very detailed and has some reference value, you can refer to the functions implemented by super () and _ init _ () when inheriting a ticket.
class Base(object):def __init__(self):print 'Base create'class childA(Base):def __init__(self):print 'creat A ',Base.__init__(self)class childB(Base):
Look at the code:@implementation son:father-(ID) init{ = [Super init]; if (self) { } return to self ;}What is self and what is super ?In dynamic methods : Self stands for "object"; In static methods : Self stands for "class"; One sentence summary is: Selfrepresents the caller of the current method;Self and super are the two reserved words provided by
These days to see the class in the inheritance will use this and super, here do a little summary, with you to communicate, there are errors please correct me ~This This is an object of its own, representing the object itself, which can be understood as: A pointer to the object itself.The usage of this can be broadly divided into 3 types in Java:1. Normal Direct referencesThis does not have to be said, this is equivalent to pointing to the current obj
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.