PROGRAMMING

MINTE9
REMEMBERS




Last update:   23-07-2021

Final

A final class can't be exended, a final method can't be overriden. Static final variables are constants (it can never change).
 RunCode
class App {
    public static void main(String[] args) {
        new Dog();
    }
}
class Animal {    
    public Animal() {}
    public final void getName() {} // Look Here
}

class Dog extends Animal {
    public Dog() {}
    //public void getName() {} // Error: override final method
}
... 7 lines
˄˄˄
 RunCode
class App {

    public static void main(String[] args) {

        new Dog();
    }
}

class Dog {

    public static final int FOO = 25; // Look Here

    public Dog() {

        System.out.println(FOO); // 25

        // FOO++; // Compile Error - Look Here
    }
}
... 6 lines
˄˄˄

Questions    
17. Packages
16 . Final
Last update:   23-07-2021

        A B C D E F
🔔
1/1