C# method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Coder Coder

    #1

    C# method

    Hi,
    How can you make sure that subclasses cannot override a method.
    In the java world, the 'final' keyword is used.



    - thanks
  • Brad Quinn

    #2
    C# method

    In order to override a method it has to be marked virtual
    in the base class. If you don't want it overridden,
    don't mark it virtual.

    If you're overriding a virtual method and you don't want
    it overriden in your subclasses, mark it sealed.
    [color=blue]
    >-----Original Message-----
    >Hi,
    >How can you make sure that subclasses cannot override a[/color]
    method.[color=blue]
    >In the java world, the 'final' keyword is used.
    >
    >
    >
    >- thanks
    >.
    >[/color]

    Comment

    • Jeff Louie

      #3
      Re: C# method

      This may help.

      Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


      2) All Methods are Not Virtual By Default. All Members are Private by
      Default.

      In Java, all methods are virtual by default and can be overridden. Not
      so
      in C#. You must explicitly declare a method virtual if you want it to
      allow
      it to be overridden. You also cannot implicitly override or hide a
      virtual
      method, but must explicitly use the override or new keyword. In Java,
      members have package level access by default. In C# all members are
      private by default.

      Regards,
      Jeff[color=blue]
      >How can you make sure that subclasses cannot override a method.[/color]
      In the java world, the 'final' keyword is used.<





      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...