“Finale Klasse Java” Code-Antworten

Finale in Java

if a variable declared as final then no class can change its value once 
it is given a value.
Ahmad Mujtaba

Java Endmethode

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

Finale Klasse Java

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

Finale Klasse Java

// 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

Ähnliche Antworten wie “Finale Klasse Java”

Fragen ähnlich wie “Finale Klasse Java”

Weitere verwandte Antworten zu “Finale Klasse Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen