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 ~First, thisThis 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 curre
) # A --> C
Print "leave B"
If the code is simple, such changes may be acceptable. However, if the code volume is large, such modifications may be disastrous.
Change to super
Super Example 1:
Class Base (object ): Def _ Init __ (Self ): Print ( " Base created " ) Class Childa (base ): Def _ Init __ (Self): base. _ Init __ (Self) Class Childb (base ): Def _ Init __ (Self):
We already know that if a member variable defined in a subclass has the same name as a member variable in the parent class, the member variable in the parent class cannot be inherited, and the member variable of the child class is called the member variable of the parent class is hidden.When a method is defined in a subclass, and the method's name, return type, number of arguments, and a method of the parent class are exactly the same, this method of the parent class is hidden (rewritten), neith
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
This article mainly introduces the usage of super in Python. This article describes the discovery and proposal of super, the implementation of super in the source code world of Python, and the continuation of the discussion of super, for more information, see
I. Problem Discovery and Proposal
In the method of a Python
Reprinted from: http://blog.csdn.net/anmei2010/article/details/4093118
1. Sub-class constructor if you want to reference super, you must put super in the first place of the function.
Class base {base () {system. out. println ("base") ;}} publicclass checketextends base {checket () {super (); // call the constructor of the parent class, which must be placed in th
.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
Super () and __init__ () implementations are similar in the case of single inheritance
Class Base (object):
def __init__ (self):
print ' base create '
class Childa (base):
def __init__ (self):
print ' creat A ',
Base.__init__ (self)
class Childb (Base):
def __init__ (self):
print ' creat B ',
super (Childb, self). _ _init__ ()
base = Base ()
a = Childa ()
B = childb ()
Output results:
B
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
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
Go to: https://mozillazg.com/2016/12/python-super-is-not-as-simple-as-you-thought.htmlWhen it comes to super, you may find it simple, not just to call the parent method. If it is so simple, then there will not be this article, and listen to me carefully. ConventionsBefore you begin, let's make an appointment with the Python version that this article uses. The default is Python 3, which means that the classe
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
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.