Quality is delighting customers
Something about constructors in Java:
Note: It is possible to use the same variable names for
the constructor which is same as that of the Global
variables. In that case you can still get the correct
output by using the "this" operator for the global
variables within the constructor.
public class operator{
int i;
int j;
//Parameterized constructor
public operator(int i,int j){
this.i=i; //here you can see that the variable i is same
this.j=j;//here this.j refers to global variable and j
//refers to the passed variable name and passed j can
//be called in other java file through the object
//reference.
}
//Blank Constructor
public operator(){
System.out.println("World Here Hello How are
you?")
}
public static void main(String[args]){
System.out.println("Hello World")
}
Note:
When you use a parameterized constructor make
sure that the variable names are different, because it
is possible that a global variable having the same
name as that of the local variable will lead to
confusion for selenium and it will give a wrong
output but no message that it is wrong, thus leading
to difficulties in debugging. Therefore the above said
practice must be followed when using constructors.
How is constructors related to testing?
In testing we write many functions inside a class file
of java. When we do so each function might
represent an action of the test case of the application.
Each such action can have variables that needs to be
initialized through constructors and these
constructors can be called in other java files (In
general testscripts). So each java file is a testscript
and they can call any global constructor from any
other java file.
© 2021 Created by Quality Testing.
Powered by