Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# inheritance

C# inheritance

Scheduled Pinned Locked Moved C#
questioncsharpoop
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ppp001
    wrote on last edited by
    #1

    Hi, How can I make a subclass not inherit its parent class method (not by private keyword), but the parent class method need to be with public keyword, coz it allow other to access it ? Thanks

    C S 2 Replies Last reply
    0
    • P ppp001

      Hi, How can I make a subclass not inherit its parent class method (not by private keyword), but the parent class method need to be with public keyword, coz it allow other to access it ? Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      you can do this public new void myMethod(); That hides the base method and replaces it with a new method on the child. You can't make a child class not impliment a method that is public on the base class, and doing so would make no sense at all. Even if you impliment the method via an interface, you will inherit it. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • P ppp001

        Hi, How can I make a subclass not inherit its parent class method (not by private keyword), but the parent class method need to be with public keyword, coz it allow other to access it ? Thanks

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        You can't prevent the method from being inherited by the derived class, but if that method is virtual, you can prevent it from being overridden in the derived class by using the sealed[^] keyword. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups