1. Mode OneA subclass invokes a method of a parent class that contains a call in the form of 2. One form is to invoke the method of the parent class within the class through inheritance, and the other is to invoke the method of the paren
);}}Test results:Port = 0 Default_port = 900In the test code, passed a number of 600, we hope Getport get is also 600, but unfortunately get a big 0!!! This problem occurs because of the ambiguity in the order of the instantiation of the Java subclass and the parent class, and the following is the correct order:1, the new one simpleserver,simpleserver the constru
here is of course to access its own member variable. 5. Super keywordThe Super keyword is used in Java to make a masked member variable or member method visible, or to refer to a masked member variable and member member method. Super is used in subclasses to access the masked members in the immediate parent class. The above code can also be written like this:Jav
class is (int *) (* (vptr of the subclass), that is, -- (int *) (* (int *) (* (int *) ( B ))).When we forcibly convert a pointer to a function, we can call it to call the parent class private function from the subclass.Run the following code:# Include Using namespace std;Class
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 the private properties and methods of the parent class? Does inheritance mean a simple
an example: what is the output of the following code when you execute new A1#includeusing namespacestd;intInitConstSTD::stringinfo) {Std::coutStd::endl; return 0;}classa{intm_x; Public: A (): M_x (init ("Init a::m_x") {init ("Call a::a ()"); }};classA1: Publica{intm_x; intm_y; Public: A1 ():M_y (Init ("Init a1::m_y")), m_x (init ("init a1::m_x"))Init ("calla1::a1 ()"The result of the printout is: Init a::m_xcall a::a () ==> is because the constructo
One, this
1, to use this, you have to be a situation of the image, otherwise it will be an error, Fatal error:using $this when not in the object context.2,this can call methods and properties in this class, or you can call methods and properties that are adjustable in the parent class
Two, self
1,self can access static and static methods in this
-- Xingyue contributes with each other ~~~ -- When Using Lua inheritance, it is very troublesome to manually remember the several layers of inheritance relationships when calling the parent class method. The code is -- Example: 1 -- base class local base = Class ("base") bas
Python neutron class to invoke a method of the parent class, which was implemented in earlier versions of Python:Class A:def __init__ (self):Print "Enter A"Print "Leave A"Class B (A):def __init__ (self):Print "Enter B"A.__init__ (self)Print "Leave B"b = B ()>>>enter BEnter ALeave ALeave Bis to use a non-binding
When doing engineering with C + +, inheritance is one of the most common features of C + + because it makes engineering reusability very high. But now there is a problem, for example, when we use the MFC library, we tend to inherit a class inside the library, but we do not look at the implementation code inside the parent cla
Extends_function () {Parent::sta_functio N (); Self::p ro_function (); echo "You request Extends_private function"; }} Error_reporting (e_all); $test = new Test1 (); $test->tank (); Subclasses and parent classes have properties and methods of the same name, and methods in subclasses are called when subclasses are instantiated. Test1::test1_function (); Test1::extends_function (); After performi
Student ("B");//The constructor of the parent class is called first, and the parent class parameterless constructor is called by default.
}
}
Output:
Base:a
Student has no args.
Base has no args.
Student:b
When there is a parent cla
1, this
1. to use this, you must be in a situation like this. Otherwise, it will report an error: Fatal error: Using $ this when not in object context.2. this can call methods and attributes in this class, or call methods and attributes that can be called in the parent class.
Ii. self
1. self can access static attributes and static methods in this
. private int age;4. Public Test () {5. Name= "Tom";6. age=20;7.}8. public static void Main (string[] args) {9. Test T = new Test ();System.out.println (T.name + "age is" + t.age);11.}12.}Class Parent {private int num = 1;. Public Parent () {System.out.println ("Now initializes the parent
One, this
1, to use this, you will have a situation of the image, otherwise it will error, Fatal error:using $this when the not in object context.2,this can call methods and properties in this class, or can call the adjustable methods and properties in the parent class
Two, self
1,self can access static properties and static methods in this
"Error:implicit Super constructor Pet () is undefined. Must explicitly invoke another constructor " Remember one point: when you construct a subclass, you are bound to call the constructor of the parent class. Because the elements in the parent class also need to be initialized.So the
Extends_function () {Parent::sta_functio N (); Self::p ro_function (); echo "You request Extends_private function"; }} Error_reporting (e_all); $test = new Test1 (); $test->tank (); Subclasses and parent classes have properties and methods of the same name, and methods in subclasses are called when subclasses are instantiated. Test1::test1_function (); Test1::extends_function (); After performi
() { OneSystem.out.println ("Animal is eating."); A } - } - the classHorseextendsanimal{ - Public voideat () { -System.out.println ("Horse is eating."); - } +}This code can be compiled. It appears to violate the sixth rule, but it's actually a bit of a coincidence. The Eat () method of the animal class cannot be inherited, so the Eat () method in the horse
When you read the QT code, you often encounter such a code:Qplayer::qplayer (Qwidget *parent): Qmainwindow (parent)Qplayer is a class, "::" followed by a constructor. But how does the Qmainwindow (parent) after the constructor ":" Be understood?We all know that in C + +, if
. Generally, the order of accessibility is (because C ++ does not have the concept of a package, packet access control is not considered for the moment, which does not affect the discussion here ):
public > protected > private
Take Java as an example:
class Base { protected void sayHello() { System.out.println("Hello in Base"); }}class Child extends Base { public void sayHello() { System.out.println("Hell
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.