Method modifiers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alreem
    New Member
    • Mar 2007
    • 1

    #1

    Method modifiers

    Hi every bady
    I need some help..

    How to prevent a method being over-ridden?
    How to require a method to be over-ridden?
    How to call method from the super class?

    If any one know help me Plz.
    Thanks,
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    Originally posted by alreem
    Hi every bady
    I need some help..

    How to prevent a method being over-ridden?
    How to require a method to be over-ridden?
    How to call method from the super class?

    If any one know help me Plz.
    Thanks,
    answer to your questions.
    1.How to prevent a method being over-ridden?
    just add the keyword 'final' in method declaration.

    eg. public final void myMethod() { bla.. bla... bla... }

    2. How to require a method to be over-ridden?
    I am not getting what u want to ask here.
    every method which is not declared final can be over-ridden.

    3. How to call method from the super class?
    an overridden method could be bypassed an the super method could be called by using super keyword; eg:- super.myMethod( );

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by sumittyagi
      1.How to prevent a method being over-ridden?
      just add the keyword 'final' in method declaration.

      eg. public final void myMethod() { bla.. bla... bla... }
      FYI - That'll get you most of the way, but there's still a workaround.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by sumittyagi
        2. How to require a method to be over-ridden?
        Make it abstract?

        Comment

        Working...