Can you make a method final, without making the whole class final?

Questions by krishna_darl   answers by krishna_darl

Showing Answers 1 - 5 of 5 Answers

kalya

  • May 22nd, 2006
 

yes.

  Was this answer useful?  Yes

Seetha Ram Janapala

  • May 22nd, 2006
 

Definitely we can make a method final, without making the whole class as final.

ex:

public class MyClass

{

    private String name = "Ram";

    public String getName()

   {   return name;   }

    final void display(String str)

   {

           System.out.println(" Hai " + str);

   } 

}

In the above class, only the display() method is 'final'. we can override the method 'getName()' in the derived class, but we can't override display(String) method.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions