Results 1 to 7 of 7

Thread: inherited classes

  1. #1

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    inherited classes

    Hi,

    Here is another one

    Take this case:

    I've these classes:

    class A{ public void M{} }
    class B : A {public override void M{} }
    class C: B {}

    I need, from class C, to call the base class method B.M() rather that A.M()...

    Is it possble to do this distinguish?

    Bye, thanx
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Code:
    using System;
    using System.Windows.Forms;
    
    namespace Test
    {
    	public class A
    	{
    		public virtual void M()
    		{
    			MessageBox.Show("Method M From Class A");
    		}
    	}
    
    	public class B : A
    	{
    		
    		public override void M()
    		{
    			MessageBox.Show("Method M From Class B");
    		}
    	}
    
    	public class C : B
    	{
    					
    	}
    
    }
    Hope that helped
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Hope that helped


    Well, thanx, but I meant: can I call

    Code:
    C.M() // call the M Method from base class A
    C.M() // call the M Method from base class B
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  4. #4
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    Nope.
    B's implementation of the M method covers A's implementation as far as the user of object C is concerned.
    -scott
    he he he

  5. #5

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103
    Nope.
    B's implementation of the M method covers A's implementation as far as the user of object C is concerned.
    So, wen I call
    Code:
    base.M()
    I always call the first ancestor method?

    Cya!
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I think that just calls the method from the last class you inherited from.
    Dont gain the world and lose your soul

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yep, you will call the M() method of the immediate parent you derived from.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width