أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Yes we can create class as final. when the class is in final the properties of the classs cant accessed to outside.
Yes we can declare a class as final .Once it became a final class it can not be extended/inherited .Doing this can confer security and efficiency benefits,so many of the Java standadrd library classes are final ,such as System,String etc.
Yes,If we mark class as final then it can't be extended.
It is blocking the inheritance characteristic by limiting OOPS behaviour.In some cases if we want the class to behave as utility class like wrapper classes(String, Maths,..), we can mark the class as final.
Yes, you can declare an entire class final. A class that is declared final cannot be subclassed. This is particularly useful, for example, when creating an immutable class like the String class.
You make a class immutable like this:
public final class Immutable{ private final String name; public Immutable(String name){ this.name = name; } public String getName() { return this.name; } }Immutable classes are useful because they're thread-safe. They also express something deep about your design: "Can't change this." When it applies, it's exactly what you need.