0% found this document useful (0 votes)
20 views7 pages

Day 17 of 30

The document contains a series of automation testing interview questions and answers, focusing on Java and Selenium. Key topics include fetching data from Excel using Apache POI, the differences between findElement and findElements in Selenium, and explanations of Java interfaces, method overloading, and method overriding. Each question is accompanied by code examples and detailed explanations of concepts.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Day 17 of 30

The document contains a series of automation testing interview questions and answers, focusing on Java and Selenium. Key topics include fetching data from Excel using Apache POI, the differences between findElement and findElements in Selenium, and explanations of Java interfaces, method overloading, and method overriding. Each question is accompanied by code examples and detailed explanations of concepts.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

On Weekend

DAY 17 : Automation Testing Interview Questions

/Junaid Aziz /Qasim Nazir


On Weekend

Q : How can you fetch data from an Excel sheet programmatically?


Ans :
Using Java (Apache POI Library):

Apache POI is a popular library for working with Excel files in Java.

Workbook workbook = WorkbookFactory.create(fis);

break;
case NUMERIC:

break;

Q : Write a code for radio button?

Ans :

public class RadioButtonExample {

// Set the path to the ChromeDriver

/Junaid Aziz /Qasim Nazir


On Weekend

// Open the HTML page

@value='male']"));
maleRadioButton.click();

@value='female']"));
femaleRadioButton.click();

WebElement otherRadioButton =

driver.quit();
}
}
}

/Junaid Aziz /Qasim Nazir


On Weekend

Q : What is the difference between findElement and findElements in Selenium?


Ans :
findElement
 Purpose: Locates the first matching element on the webpage.
 Return Type: Returns a single WebElement.
 Behavior if No Element Found: Throws a NoSuchElementException if the specified element
is not found.
 Usage: Best suited when you are sure that there will be only one matching element or you
only care about the first occurrence of the element.

Example :

searchBox.sendKeys("Selenium WebDriver");

findElements

 Purpose: Locates all matching elements on the webpage.


 Return Type: Returns a List of WebElements (List<WebElement>).
 Behavior if No Element Found: Returns an empty list (List<WebElement> with size 0)
instead of throwing an exception.
 Usage: Best suited when you need to find multiple elements or verify the presence of
elements.

Example:

for (WebElement link : links) {

Q : What is an interface in Java, and how is it used?


Ans :
An interface in Java is a blueprint of a class that defines a contract for what a class must do, but not how
it does it. It is a mechanism to achieve abstraction and multiple inheritance in Java. Interfaces can
contain:

 Abstract methods: Methods without implementation (prior to Java 8).


 Static methods: Fully implemented methods that belong to the interface (introduced in Java
8).
 Default methods: Fully implemented methods that can be overridden by implementing
classes (introduced in Java 8).
 Constants: Variables declared in an interface are implicitly public, static, and final.

/Junaid Aziz /Qasim Nazir


On Weekend

default void defaultMethod() {

static void staticMethod() {

Q : Explain method overloading and method overriding with examples.


Ans : 1.

Method Overloading
Definition:
Method overloading allows a class to have multiple methods with the same name but different
parameter lists (number, type, or order of parameters).

Key Points:

 Happens within the same class.


 Return type does not matter; only the parameter list is considered.
 Provides compile-time (static) polymorphism.

public double add(double a, double b) {

public class Main {

/Junaid Aziz /Qasim Nazir


On Weekend

System.out.println(calc.add(5, 10)); // Calls add(int, int)

}
}

2. Method Overriding

Definition:
Method overriding allows a subclass to provide a specific implementation for a method that is
already defined in its superclass.

Key Points:

 Happens between a superclass and a subclass.


 The method in the subclass must have:
o The same name, return type, and parameters as the method in the superclass.
 Provides runtime (dynamic) polymorphism.
 Requires inheritance.

1. Method Overloading

Definition:
Method overloading allows a class to have multiple methods with the same name but different
parameter lists (number, type, or order of parameters).
Key Points:

 Happens within the same class.


 Return type does not matter; only the parameter list is considered.
 Provides compile-time (static) polymorphism.

2. Method Overriding

Definition:
Method overriding allows a subclass to provide a specific implementation for a method that is
already defined in its superclass.

Key Points:

 Happens between a superclass and a subclass.


 The method in the subclass must have:
o The same name, return type, and parameters as the method in the superclass.
 Provides runtime (dynamic) polymorphism.
 Requires inheritance.

Rules for Overriding:


1. Access Modifier: The overriding method cannot have a more restrictive access modifier than

/Junaid Aziz /Qasim Nazir


On Weekend

the overridden method. For example, if the superclass method is protected, the subclass
method cannot be private.
2. Annotations: Use @Override to indicate the method is overridden (optional but
recommended).
3. Exceptions: The overriding method cannot throw a broader exception than the overridden
method.
4. Static/Final Methods: Cannot be overridden.

class Animal {

public void sound() {

public class Main {

myAnimal.sound(); // Calls Animal's sound()

Animal myDog = new Dog();


myDog.sound(); // Calls Dog's sound()

/Junaid Aziz /Qasim Nazir

You might also like