10_Java_Interview_Questions_And_Answers
10_Java_Interview_Questions_And_Answers
System.out.println("Engine started");
System.out.println("Trunk opened");
}
System.out.println("Bird is singing");
System.out.println("Sparrow is singing");
}
public class Main {
Here, Sparrow overrides the sing method of Bird. Despite referring to Sparrow with a
Bird reference, the overridden method in Sparrow is called.
Abstraction
Abstraction is the concept of hiding complex implementation details and showing only
the necessary features of an object. It can be achieved using abstract classes and
interfaces.
Example:
abstract class Animal {
System.out.println("Animal is eating");
System.out.println("Bark");
if (amount > 0) {
balance += amount;
balance -= amount;
return balance;
}
}
account.deposit(1000);
account.withdraw(500);
In this example, the balance of the BankAccount is kept private. It can only be modified
through the deposit and withdraw methods and read through the getBalance method,
showcasing encapsulation.
Overloading:
Question: How would you create overloaded methods for finding elements using
Selenium WebDriver?
Answer:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Overriding:
Question: Describe a scenario where you would override the toString() method in a
custom WebElement class for logging purposes in Selenium.
Answer:
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
Inheritance:
Question: How does the Page Object Model (POM) utilize inheritance in Selenium
tests?
Answer:
Enums:
Question: Explain how you could use enums to define browser types for cross-browser
testing in Selenium.
Answer:
Generics:
Question: How would you create a generic method to handle dynamic waits in
Selenium?
Answer:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebDriver;
Array:
Question: How could you use arrays in Selenium to store multiple element locators?
Answer:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
List:
Question: How would you use lists in Selenium to store a collection of WebElements?
Answer:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.List;
Map:
Question: Describe a scenario where you would use a map in Selenium to store test
data for data-driven testing.
import org.openqa.selenium.WebDriver;
import java.util.Map;
These scenarios demonstrate how core Java concepts can be applied in the context of
https://www.linkedin.com/posts/sidharth-shukla-77b53145_sidpost-testautomation-automation-
activity-7188447406403784705-Phgd?utm_source=share&utm_medium=member_desktop
👉Java program to input name, middle name and surname of a person and print only the initials.
👉What is a singleton Design Pattern? How do you implement that in your framework?
👉Write the Top 5 test cases for Booking Coupons.
👉What is delegate in Java and where do you use Delegate in your Framework?
👉What are the Major challenges that come into the picture when you do parallel testing using
TestNG and Grid?
👉How do you integrate your automation framework with the Jenkins pipeline?
👉What will happen if we remove the main method from the java program?
👉Write the logic of retrying the failed test case with a minimum 3 numbers of time in
👉How do you set priorities for test automation, which test needs to be automated first?