Package fifth day; public class Person {public void say () {System.out.println ("I am the Say method for person");}}The subclass student is as follows:The fifth day of the package, public class Student extends person{//overrides the parent class's
The only difference between your sub-classes is the function that returns constant data. Modify these functions so that they return a (new) read-only value in the superclass and then destroy the subclass.
Motivation: the purpose of creating a
Previously thought the This keyword refers to the caller object, but this time really understand that this represents the current object, but point to the caller object, is actually a polymorphic usage, as follows: B inherits A, in B calls a method
This article mainly introduces the sequence and pitfalls of variable instantiation of subclasses and parents commonly used in Java, and discusses this problem in conjunction with an Android instance. You should try to avoid this trap in future
Knowledge: No matter whether there are any virtual functions in the parent class, you can define the parent class pointer to the subclass instance. If no virtual function exists in the parent class, the parent class pointer is used to access only
# Include using namespace STD; Class A {public: A () {cout func1 (); B-> func2 (); B-> func3 (); A-> func1 (); A-> func2 (); a-> func3 (); getchar (); Return 0 ;}
Output result:
1. Before creating a subclass to call the constructor of the
AAs can be seen from the source code, subclasses can be directly assigned to the base class ("base class variable = Subclass Object"), the reference type of the base class to be passed to the subclass must pass the cast ("sub-class variable =
Packagetest; Public classCar {Private intCarmoney;//Car Rental PrivateString Carname;//Car name Private intCarnumb;//Car Serial number Private intCarrynum;//Cargo Capacity Private intPassengernum;//number of passengers
The instantiation process for subclasses:All constructors in a subclass access the constructor of the parent class's Hollow parameter by default.Class Parent{Parent () {System.out.println ("Parent class run");}}Class Children extends Parent{Children
When initializing a subclass, the constructor of the parent class must run
Because there is an implicit statement super () in the first row of the constructor of the subclass, all constructors of the subclass default to the first row of super
C ++: access the private functions of the parent class from the subclass.Transferred from longyin pavilion Co., http://blog.sina.com.cn/dragonsound. Thanks to the work of the original author(22:44:21)Tags: virtual function c private f1 it as we all
Reference: http://tieba.baidu.com/p/1167962877
one, the parent class does not write the constructor,
The constructor of a subclass can be written in "any" form without regard to the constructor of the parent class. For example: The parent class is
In today's succession review, I have a new insight into the attributes of inheritance------> Subclass inherits the parent class, inherits the parent class's methods and properties, and looks at the following figure
Inheritance---> Properties (two
I always wanted to write something about subclass, because subclass is a basic and practical technology for interface programming. However, a good application instance has never been found, because this example cannot be too complex, otherwise it is
Subclass instantiation involves two steps:
. class-relatedStatic contentInitialization;
* Parent class and Child class:
1. Static attributes of the parent class;
2. Static block of the parent class;
3. Static attributes of subclass;
4.
Subclass to Parent class (parent class reference to child class object)A subclass can be converted to a parent class, with the following parent class Fruittest and its subclasses appletestclass fruittest { = "Fruittest"; Public String get ()
Town Field Poem:Cheng listens to the Tathagata language, the world name and benefit of Dayton. Be willing to do the Tibetan apostles, the broad show is by Sanfu mention.I would like to do what I learned, to achieve a conscience blog. May all the
Public classsuperclass{ Public voidPrintA () {System.out.print ("Superclass-printa"); PRINTB (); } Public voidPrintb () {System.out.print ("Superclass-printb"); }} Public classChildClassextendssuperclass{ Public voidPrintA ()
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.