java keyword This, super use summary First, this The Java keyword This can only be used in a method method body. When an object is created, the Java Virtual Machine (JVM) assigns a pointer to the object that refers to itself, which is the name of this pointer. Therefore, this can only be used in non-static methods in the class, static methods and static code blocks must never appear in this, which is explained in the article "Java keyword static, fin
First of all, we have a question about the Python super class in StackOverflow as the beginning of this article, the problem is basically this:>>>classA (object): ...def __init__(self): ...Print "A Init"... super (a,self) .__init__()... >>> >>> A =A () a init>>>classB (object): ...def __new__(self): ...Print "B New"... super (b,self) .__new__()... >>> >>> B =B ()
Super is used to solve multiple inheritance problems, it is not a problem to call the parent class directly with the class name when using single inheritance, but if multiple inheritance is used, it involves various problems such as lookup order (MRO), repeated invocation (Diamond inheritance). In short, the experience left behind is: to maintain consistency. Either call the parent class with the class name, or use
Note: python3 is the runtime environment. The example is taken from Chapter 8th of pythoncookbook. In python, there are two main methods to initialize the parent class if the subclass is to be implemented. The first method is to directly use the parent class name, and the second method... quot; gt; lt; metaname quot; keywords quot; content quot; call details of pythonsuper in multi-inheritance. note: python 3 is the runtime environment, the example is taken from Chapter 8th of python cookb
Summarize the keyword this and the super usage. AUTHOR:ZJ 07-3-12blog: [Url]http://zhangjunhd.blog.51cto.com/[/url]1. What is super? What is this? The Super keyword denotes the meaning of the super (parent) class. The This variable represents the object itself. 2. Use Superthis to call member variables and methods you
Two special variables in Java: this and super -- general Linux technology-Linux programming and kernel information. The following is a detailed description. There are two very special variables in Java: this and super. These two variables do not need to be declared before use. This variable is used inside a member function and points to the current object. The current object refers to the object that calls
Class A:def __init__ (self):Print "Enter A"Print "Leave A"Class B (A):def __init__ (self):Print "Enter B"a.__init__ (self) # old methodPrint "Leave B">>> B = B ()Enter BEnter ALeave ALeave BThe disadvantage of this is that when the parent class of a subclass changes (such as when the parent class of Class B changes from A to C), the entire class definition must be traversed, replacing all the class names of the unbound methods.Since Python 2.2, Python has added a keyword
Python super
I. Problem Discovery and Proposal
In the method of a Python class, to call a method of the parent class, before Python 2.2, the usual method is as follows:
Code Segment 1:
Class:Def _ init _ (self ):Print "enter"Print "leave"
Class B ():Def _ init _ (self ):Print "enter B"A. _ init _ (self)Print "leave B"
>>> B = B ()
Enter BEnterLeaveLeave B
That is, use non-bound class methods (Methods referenced by class names), and introduce the objec
Python 2.2, Python has added a keyword "super" to solve this problem. The official documentation for python 2.3 is as follows:
Super (type [, object-or-type])
Return the superclass of type. If the second argument is omitted the super objectReturned is unbound. If the second argument is an object, isinstance (OBJ, type)Must be true. If the second argument is a ty
Super Rabbit optimization Wang software is a powerful system optimization software developed by Super Rabbit for beginners after three years of improvement. In the latest version 5.0, all Optimization-related functions are available, allowing anyone to easily connect to their own computers. Whether you are using Windows 95/98/me or Windows 2000/XP, the optimizer can automatically analyze the system and prov
custom initialization method, which has more limitations. Then it [class alloc] init] will be more convenient, of course, [class alloc] init] the design is due to historical reasons.Why do you write that?
1234567
- (instancetype)init { if (self = [super init]) { //Custom initialization } return self ; }
We know that we are alloc returning a valid uninitialized object instance. For self alloc pointers that are return
also due to historical reasons.Why do you write that?- (instancetype) init{ if (self = [Super init]) { // Custom Initialization } return self ;}We know that Alloc returns a valid uninitialized object instance. For self is a pointer returned by Alloc and can be accessed within all method scopes.But for super, it's just a "compiler indicator" that tells the compiler to search for the impleme
This and super must be placed in the first row of the constructor, because the initialization action is done first.The first row in the constructor in the parent class also has an implicit super () statement, which points to the parent class of all classes, object./////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////
1 /*2 Super Keyword:3 4 The Super keyword represents a reference to the parent class space. 5 6 The Super keyword works:7 1. When the child parent class has a member with the same name, the child class is accessed by default as a member of the subclass, and the members of the parent class can be accessed through the Super
Http://www.cocoachina.com/macdev/objc/2011/0124/2602.html
In the class implementation of objective-C, we often see the two keywords "self" and "super". Taking the previous OOP language experience as an example, C ++ assumes that self is equivalent to this, super is equivalent to calling the parent class method, which seems easy to understand. The following code is used as an example:
@ Interface person: ns
Document directory
Truth
One more step
Furthor more
In the class implementation of objc, we often see the two keywords "self" and "super". Taking the previous oop language experience as an example, take c ++. self is equivalent to this, super is equivalent to calling the parent class method, which seems easy to understand.
The following code is used as an example:?
1234567891011121314151617
InJava has two very special variables: this and super, which do not need to be declared before use. This variable is used inside a member function and points to the current object. The current object refers to the object that calls the method currently being executed. A super variable is a constructor that directly points to a super class and is used to reference
We all know that this and super call constructors must be placed in the first sentence, and today the classmate asked me a question of a little meaning.So: How do I explicitly initialize a parent class with super in a subclass and initialize the subclass with this? -------------------------------------------------------------------------------------First of all, we must realize that two points:1. The
* SUPER () and this () are similar, except that super () calls the constructor of the parent class from the subclass, and this () calls other methods within the same class.4. The similarities and differences between Super and this:1) Super (parameter): Call one of the constructors in the base class (should be the first
Http://www.cocoachina.com/macdev/objc/2011/0124/2602.html
In the class implementation of objective-C, we often see the two keywords "self" and "super". Taking the previous OOP language experience as an example, C ++ assumes that self is equivalent to this, super is equivalent to calling the parent class method, which seems easy to understand. BelowCodeFor example:
@ Interface person: nsobject {Nsstring
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.