In this case, why not an error occurs: Point Rp = new rectpoint (12, 15 );

Source: Internet
Author: User
Test these Program A problem is found. Code The program can use:

Using system;

Static class M
{
Static void main ()
{
Point Rp = new rectpoint (12, 15 );
RP. Show ();
}
}

Class Point
{
Protected int m_x;
Protected int m_y;

Public Virtual void show ()
{
Console. writeline ("x =" + m_x.tostring () + "Y =" + m_y.tostring ());
}
}

Class rectpoint: Point
{
Public rectpoint (INT x0, int y0)
{
M_x = x0;
M_y = y0;
}

Public override void show ()
{< br> console. writeline ("rect:");
base. show ();
}< BR >}< br> the problem is from row 7th: Point Rp = new rectpoint (12, 15 );, I think the correct method should be rectpoint Rp = new rectpoint (12, 15); but when copying code, the point is not changed to rectpoint, but the program runs normally, the running result is the show of rectpoint. This problem was discovered later. Can an object be defined as its parent class? After the definition is complete, although it executes all the code of the subclass, the compiler will not allow the new sub-classes to pass, that is, the object can only execute the member functions of the parent class.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.