HCLTech
10+ Interview Questions and Answers
Q1. what is the output of below code class Animal{ Animal(){ System.out.println("animal is created") } class Dog extends Animal{ Dog(){ System.out.println("Dog is created")} class TestSuper4{ public static void mai...
read moreThe output of the code will be 'animal is created' followed by 'Dog is created'.
The code defines a class Animal with a constructor that prints 'animal is created'.
It also defines a class Dog that extends Animal, with a constructor that prints 'Dog is created'.
In the main method, an instance of Dog is created, which will trigger the constructors of both Animal and Dog classes.
Q2. Which is valid or invalid a. ChromeDriver driver=new ChromeDriver(); b. WebDriver driver=new ChromeDriver(); c. WebDriver driver2=new WebDriver(); driver2=new ChromeDriver();
Option a is valid, option b is valid, option c is invalid.
Option a is valid because ChromeDriver is a subclass of WebDriver, so it can be assigned to a WebDriver reference.
Option b is valid because ChromeDriver is a subclass of WebDriver, so it can be instantiated using a WebDriver reference.
Option c is invalid because WebDriver is an interface and cannot be instantiated directly. It can only be used as a reference type.
Q3. difference between getwindowhandle and getwindowhandles() and what is output type
getwindowhandle returns the handle of the current window, getwindowhandles() returns handles of all open windows
getwindowhandle returns a single window handle, while getwindowhandles() returns a set of window handles
getwindowhandle is used to switch between windows in Selenium WebDriver
Output type of getwindowhandle is String, while output type of getwindowhandles() is Set
Q4. Find the combained charected in the given testing exmple : " Testing Testing Testing" , cobained text is "te"
The combined characters in the given testing example 'Testing Testing Testing' is 'te'.
Iterate through the text and check for consecutive characters 'te'.
Combine the characters 'te' whenever they are found together.
Return the combined text 'te' as the result.
Q5. Program to sort the input in descending order without using inbuild method/functions
Sort input array of strings in descending order without using inbuilt functions
Iterate through the array and compare each element with the rest to find the largest element
Swap the largest element with the first element, then repeat the process for the remaining elements
Continue this process until the array is sorted in descending order
Q6. Output of this : String name="Hello"; name=name+"There"; system.out.println(name)
The output will be 'HelloThere'
Concatenation of 'Hello' and 'There' results in 'HelloThere'
The final string is printed using System.out.println()
Q7. StringBuffer buffer=new StringBuffer("Hello") buffer.append("There"); System.out.println(buffer);
The code creates a StringBuffer object with 'Hello' and appends 'There' to it before printing the final string.
StringBuffer is mutable, so the original 'Hello' string can be modified
The append() method adds the specified string to the end of the buffer
The final output will be 'HelloThere'
Q8. Difference between String and StringBuilder?
String is immutable, while StringBuilder is mutable and more efficient for concatenating strings.
String is immutable, meaning its value cannot be changed once it is created.
StringBuilder is mutable, allowing for modifications to the string without creating a new object.
StringBuilder is more efficient for concatenating multiple strings as it does not create new objects each time.
Example: String str = "Hello"; StringBuilder sb = new StringBuilder("Hello");
Q9. difference between findElement and findElements
findElement returns the first matching element on the page, while findElements returns a list of all matching elements.
findElement returns a single WebElement matching the locator provided
findElements returns a list of WebElements matching the locator provided
findElement will throw NoSuchElementException if no element is found, while findElements will return an empty list
Q10. Find the 2nd largest number in the given array
Find the 2nd largest number in the given array
Sort the array in descending order
Get the element at index 1, which will be the 2nd largest number
Interview Process at null
Top Automation Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month