Using final keyword to stop change - Java Object Oriented Design

Java examples for Object Oriented Design:final

Introduction

A final keyword that serves three purposes.

final on variable creates a constant whose value can't be changed once it has been initialized.

A final method is a method that can't be overridden by a subclass.

For example:

class SpaceShip
{
    public final int getVelocity()
    {
        return this.velocity;
    }
}

A final class is a class that can't be used as a base class.

public final class BaseBall
{
}

Related Tutorials