“Java Final Class” Ответ

Что это значит, когда создать окончательную переменную в Java

First of all, final is a non-access modifier applicable only to 
a variable, a method or a class

When a variable is declared with final keyword, its value can’t be modified, 
essentially, a constant. This also means that you must initialize a 
final variable. If the final variable is a reference, this means that 
the variable cannot be re-bound to reference another object, but internal 
state of the object pointed by that reference variable can be changed 
i.e. you can add or remove elements from final array or final collection. 
  It is good practice to represent final variables in all uppercase, using 
  underscore to separate words.
Kamran Taghaddos

Ява финальный метод

class FinalDemo {
    // create a final method
    public final void display() {
      System.out.println("This is a final method.");
    }
}

class Main extends FinalDemo {
  // try to override final method
  public final void display() {
    System.out.println("The final method is overridden.");
  }

  public static void main(String[] args) {
    Main obj = new Main();
    obj.display();
  }
}
SAMER SAEID

Финальный класс Java

You cannot extend a final class. If you try it gives you a compile time error.
coder

Java Final Class

// create a final class
final class FinalClass {
  public void display() {
    System.out.println("This is a final method.");
  }
}

// try to extend the final class
class Main extends FinalClass {
  public  void display() {
    System.out.println("The final method is overridden.");
  }

  public static void main(String[] args) {
    Main obj = new Main();
    obj.display();
  }
}
SAMER SAEID

Ответы похожие на “Java Final Class”

Вопросы похожие на “Java Final Class”

Больше похожих ответов на “Java Final Class” по Java

Смотреть популярные ответы по языку

Смотреть другие языки программирования