------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
Java programming-this and super
8.8 this and super
The following describes how to use the this and super keywords. By using the this and super keywords in a program, you can easily reference a lot of content inside the class and understand the implementation principle of object-oriented, it is easier to understand the
.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
Summary
The navigation menu is not necessarily a simple collection of text links, which enriches the level of navigation information and even the hierarchy of the entire site's content. Because the general Pull-down menu has a lot of usability problems, prompting mega Drop-down menu came into being, because this kind of menu is really cow x, so I call it Super Pull-down menu. The related test proves that the Supe
Java-based super and uper
I have briefly explained the basic inheritance usage. Now I want to add something that is easily overlooked in inheritance, such as super.
, I added an output statement to the constructor of the parent class (Father), but I did nothing in the Child class .. however, when the new subclass object is used, the content in the parent class constructor is output... why ??
Are you confu
Linux virtual file system four main objects:1) Super Block2) Index node (inode)3) Catalog entry (dentry)4) Document object (file)A process that refers to various objects as it operates on a file is as follows:by Task_struct get files_struct, then through the file descriptor (int fd) to obtain the corresponding file object (**FD), then get the Directory item object (Dentry), and finally get the Index node object (inode), The object includes actions rel
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
The ability to implement super () and __init__ () is similar for single-inheritance
Class Base (object):d EF __init__ (self):p rint ' base create ' class Childa (base):d EF __init__ (self):p rint ' creat A ', base.__ Init__ (Self) class childb (base):d the EF __init__ (self):p rint ' creat B ', super (childb, self). __init__ () base = Base () A = Childa () b = childb ()
Output Result:
Base Createcreat A B
For example, classChild (Parent): def _ init _ (self): Parent. _ init _ (self), for example
class Child(Parent): def __init__(self): Parent.__init__(self) Reply content: the answer to your question is yes, and there is no difference. However, I don't feel good enough to answer this question.
To talk about super, we should first ignore the interference brought by the name "super.
Do not t
The difference between super () and _ init _ () in python classes is that python _ init __
The functions implemented by super () and _ init _ () for single inheritance are similar.
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
this:First, call another constructor using this (parameter list). This is only used in the constructor of the class and cannot be used in other places.2. When the name of a function parameter or local variable in the function is the same as that of a member variable, the member variable is blocked. To access the member variable, you must use "this. to reference member variables. Of course, without the same name, you can directly use the name of the member variable instead of this. If you use th
Original address: https://www.cnblogs.com/hasse/p/5023392.htmlThese 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 ~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
The article turns from
@implementation Son:father
-(ID) init{
self = [super init];
if (self) {
} return
self;
}
This is an ordinary to initialization method that invokes the Init implementation of the parent class before the subclass implements initialization. Based on this initialization method, we compare the self and Super keywords from three aspects. what self is and what
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
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.