answersLogoWhite

0

You would make a class Final in Java if you do not want anybody to inherit the features of your class.

If you declare a class as Final, then no other class can extend this class.

Example:

public final class X {

....

}

public class Y extends X {

....

}

Here Y cannot extend X because X is final and this code would not work.

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Can you make a class final in java?

yes of course... using the final keyword


Do you use virtual functions in Java?

Every method in java that isn't a class (static) method is automatically "virtual." If you want to disable virtual overrides, make the method "final" in the base class.


In Java can an interface be final?

No. Interfaces themselves cannot be instantiated, so in order to be useful you must make a subclass. The final keyword will make a class unable to be extended, which would defeat the point of using an interface.


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 prevent inheritance in java without final?

Make the constructor private. Uhm, how would you make a instance of this class then? Why don't you want inheritance? I don't understand!Answer:You can create the class without the public declaration. In such a case the access for that class would be default and hence you cannot extend that specific class outside its package. Still you can extend this class within its package.The purpose of having the final keyword is to ensure that the class is not inherited. doing it without final is like touching your nose around your head when you can do it straightaway...


How do you prevent method overriding in java?

Use the word "final" directly preceding your method declaration. The presence of final keyword directs java to ensure that, this particular method would not be overridden by any of its child classes.


What is java file in java?

A java file contains the code you write. One java file contains one class so for example when I want to make a class called Person, the source code is saved in Person.java


How you make a project in java?

You create a text file with a .java extension. Then you put a proper class definition.


How can we make sure (pragmatically) that a class will have no further child classes. Which programming stmt will do this in Java and C?

How can we make sure (pragmatically) that a class will have no further child classes. Which programming stmt will do this in Java and C++?


A final class can have instances?

Yes. You cannot inherit a final class but very well instantiate a final class


What do you get when you compile a java program?

The java interpreter or JVM (Java Virtual Machine) is not able to execute the java source code for a program. The java source code first needs to be compiled into bytecode that can be processed by JVM. Producing bytecode make the program platform independent as each platform has its own JVM. It is also possible to directly write bytecode, bypassing the need to compile, but that would be tedious job and also not good for security purpose as the compiler checks for various errors in a program.


How do you make a java class?

You write the source code, in a text editor, or better in a special IDE. The source code should have the extension ".java". You can have several classes in the same file. Then you compile the class to bytecode; this creates a file with extension ".class".