answersLogoWhite

0

When do you declare a method or class final?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

if we declare a method as final then it can be changed.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When do you declare a method or class final?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the relationship between inheritance methods and the keyword final?

They are inversely related. That is: If you declare a method as final you cannot overridden in the child class If you declare a class as final you cannot inherit it in any other class.


When do you declare a method final in java?

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method. I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)


How can you create a class which cannot be inheritable?

Declare it final.


How do you prevent class extending in java?

Declare the class as final. final class A{ ... }


When do you declare a variable method and a class final?

When There is No Need to Change the Values of the Variables In Entire lifetime of That variables then we must use that Variable as Final Variable.


Can you declare main as final or not and why?

Yes you can. Try this: public class TestMain { /** * @param args */ public static final void main(String[] args) { System.out.println("Inside final mail method..."); } } It will print "Inside final mail method..." in the console.


Can you have a final abstract class?

No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.Combining them would lead to an unusable class, so the compiler will not let this happen.


When do you declare a class as final?

By using the final keyword in the class declaration statement. Ex: public final class Test {...}


How do you prevent extending a class in java?

You can declare a class as "final".


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


Discuss final method and final classes?

a method declared final can not be overridden, and a class declared as final can not be extended by its sub class.


Can you override an instance method and make it final?

No. Once a method is declared final in a class, no derivative of that class can override that method.