Book Image

Hands-On Automation Testing with Java for Beginners

Book Image

Hands-On Automation Testing with Java for Beginners

Overview of this book

Java is one of the most commonly-used software languages by programmers and developers. Are you from a non-technical background and looking to master Java for your automation needs? Then Hands-On Automation Testing with Java for Beginners is for you. This book provides you with efficient techniques to effectively handle Java-related automation projects. You will learn how to handle strings and their functions in Java. As you make your way through the book, you will get to grips with classes and objects, along with their uses. In the concluding chapters, you will learn about the importance of inheritance and exceptions with practical examples. By the end of this book, you will have gained comprehensive knowledge of Java.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

The final keyword


First, we will create a new class. If we declare any variable as final, that means the value cannot be changed again. Let's consider the following code:

package coreJava;

public class finaldemo {

    public static void main(String[] args) {
        //TODO Auto-generated method stub
        final int i=4; //constant variables
    }
}

As you can see, we have declared the integer value as 4. This means we cannot change this value to another number. If we try to do that, it throws an error saying Remove 'final' modifier of 'i'. This keyword is useful if we want a value to be constant. 

If we mark a class as final, it will throw an error because when we change the access mode to final, we are not able to use that as a parent class. In other words, we will not be able to inherit our properties from it. If we want to inherit our properties, we need to change it back to public. The key logic for the final keyword is that, once written, we cannot override final methods. So these...