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

Constructors


The constructor is one of the most important concepts in the Java programming language. Thus, before we see an example, let's understand what a constructor is.

A constructor executes a block of code whenever an object is created. That means that, whenever we create an object for the class, automatically a block of code will get executed. In other words, a constructor is invoked whenever an object is created.

So where is a constructor used and how do we define it? A constructor should be written, it's just like a method, but the only difference between a method and a constructor is that a constructor will not return any values, and the name of the constructor should always be a class name.

To create a constructor for this class, we will write the following code syntax:

public class constructDemo()
{
//
}

From the preceding code syntax, it is evident that whatever is written in this constructor will be executed whoever creates an object and calls the constructor. If we create an object...