Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6779233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:21:39+00:00 2026-05-26T16:21:39+00:00

class clsTestParent { public void testNoAbstract() { Console.WriteLine(Parent Method Call); } } class clsDerivedTest

  • 0
class clsTestParent
    {
       public void testNoAbstract()
        {
            Console.WriteLine("Parent Method Call");
        }
    }

    class clsDerivedTest : clsTestParent
    {
     public void testNoAbstract()
        {
            Console.WriteLine("Child Method Hiding Parent Method");
        }
    }

            clsTestParent objParent = new clsTestParent();
            clsTestParent objOfParentFromDerived = new clsDerivedTest();
            clsDerivedTest objDerived = new clsDerivedTest();

            objParent.testNoAbstract();
            objOfParentFromDerived.testNoAbstract();
            objDerived.testNoAbstract();

Output:
Parent Method Call
Parent Method Call
Child Method Hiding Parent Method

But when I declare testNoAbstract() as virtual and over ride in derived class , then the out put will be as below:

Parent Method Call  
Child Method Hiding Parent Method
Child Method Hiding Parent Method

Earlier I used to think , we can only redefine a method in derived class , if that is defined as abstract or virtual , but as can see now , we can hide the parent class method just by redefining it in derived class.

Though , I can see , the difference in output by changing the code , I would like to know , What are the differences between above two methods and why it yields different out put.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:21:40+00:00Added an answer on May 26, 2026 at 4:21 pm

    If youll ever do clsTestParent a = new clsDerivedTest () – you’ll never be able to execute the one in the clsDerivedTest class !!!!

    Thats the difference and thats why the compiler warns you.

    you’ll actually gonna do that if you wish to preform a Polymorphism architecture.

    Microsoft tells you : ” listen , you direved a class , and we will give you all the public things etc but we dont know how do you want to implement the methods … if you’ll use the virtual + override – youll be able to execute a different method via the instace type. and if you wont override – so the function of the father will always be executed…. its your choice … we are warning you “… and they do warn

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Parent { public function __construct($method) { call_user_func(array($this, $method), 1); } } class Child
I have the Parent Class : class clsTestParent { protected int x; public void
class Program { static void Main(string[] args) { var x = new Program(); Console.Write(x.Text);
class A : public QObject{ Q_OBJECT signals: void a_sig(); public: A(){ } public slots:
class app { public int x = 3; static void Main(string[] args) { }
class Program { static void Main(string[] args) { MyDatabaseEntities entities = new MyDatabaseEntities(); var
class Object { }; Class Derived : public Object { }; boost::shared_ptr<Object> mObject(new Derived);
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class Connection { public: typedef boost::shared_ptr<Connection> pointer; static pointer create(boost::asio::io_service& io_service){return pointer(new Connection(io_service));} explicit
class foo { public void bar(int i) { ... }; public void bar(long i)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.