Java Interview Questions for Selenium Automation Testing

Java Interview Questions for Selenium Automation Testing | This tutorial has listed 100++ frequently asked interview questions based on important topics during Java technical interview round for Selenium automation testing.

During an interview, the same question can be asked in many different ways. So, be confident in an interview. Interviewers are interested in listening not just the correct answer, but also your knowledge about the topic.

Here, listed Java interview questions for Selenium automation testing with the best possible answers will be helpful to get complete knowledge and tackle the interview.

Your approach towards understanding the questions and sharing your answers plays an extremely important role in an interview success.

Core Java interview questions for Selenium automation testing

Core Java Interview Questions based on OOPs Concepts

1. What are the core OOPs concepts or main principles of object-oriented programming?

🅰 The core concepts of OOPs are

Abstraction: Protecting data of a class from being accessed by members of another class

Encapsulation: Hiding data of class from other classes

Inheritance: Using code written in a class inside other classes

Polymorphism: Using various methods with same name

2. What is Encapsulation in Java?

🅰 The process of binding data and corresponding methods (behavior) together into a single unit is called encapsulation.

3. How to achieve or implement encapsulation in Java? 

🅰 There are two points thereby we can achieve or implement encapsulation in Java program.
1. Declaring instance variable of class as private so that it cannot be accessed directly by anyone from outside the class.
2. Provide the public setter and getter methods in the class to set/modify the value of variable.

4. What is Data hiding in Java? How to achieve it programmatically?

🅰 Data hiding is a technique by which we prevent to access data members (variables) directly from outside the class so that we can achieve security on data.

By declaring data members (variables) as private, we can achieve or implement data hiding.

5. What is tightly encapsulated class in Java?

🅰 If each variable is declared as private in the class, it is called tightly encapsulated class in Java.

6. What would happen if we do not use Encapsulation in a program?

🅰 If we don’t use encapsulation in a program, fields will not be private and could be accessed by anyone from outside the class.

7. What is getter and setter method in Java?

🅰 A method that is used to retrieve/get the value of a variable or return the value of the private member variable is called getter method.

A method that is used for updating or setting the value of a variable is called setter method.

8. Explain inheritance.

🅰 The technique of creating a new class by using an existing class functionality is called inheritance. In other words, inheritance is a process where a child class acquires all the properties and behaviors of parent class. The existing class is called parent class and the new class is called child class.

9. What is Is-A relationship in Java?

🅰 Is-A relationship represents inheritance. It is implemented using “extends” keyword. It is used for code reusability. All the classes extends java.lang.object by default. This is a very good example of Is-A relationship.

10. Which class in Java is super class of every other class?

🅰 Object class is the superclass of every other class in Java.

11. How is Inheritance implemented/achieved in Java?

🅰 Inheritance can be implemented or achieved by using two keywords:

extends: extends is a keyword that is used for developing the inheritance between two classes and two interfaces.

implements: implements keyword is used for developing the inheritance between a class and interface.

12. What are the uses of inheritance?

🅰 We use inheritance in java for the following reasons:
a. We can reuse the code from the base class.
b. Using inheritance, we can increase features of class or method by overriding.
c. Inheritance is used to use the existing features of the class.
d. It is used to achieve runtime polymorphism i.e method overriding.

13. What are the advantages of Inheritance?

🅰 The advantages of inheritance are as follows:
1. One of the main advantages is that we can minimize the length of the duplicate code in an application by putting the common code in superclass and sharing amongst several subclasses.

2. Due to reducing the length of the code, redundancy of the application is also reduced.

14. Why Java does not support multiple inheritance through class?

🅰 Multiple inheritance means that one class extends two superclasses or base classes but in Java, one class cannot extend more than one class simultaneously. At most, one class can extend only one class.

Therefore, to reduce ambiguity, complexity, and confusion, Java does not support multiple inheritance through class.

For more detail, go to this tutorial: Types of Inheritance in Java

15. How does multiple inheritance implement in Java?

🅰 Multiple inheritance can be implemented in Java by using the interface. A class cannot extend more than one class but a class can implement more than one interface.

16. What are the uses of super keyword in Java?

🅰 super keyword is a reference variable that refers to an immediate superclass object. It is used for the following purposes:
a. To refer immediate parent class instance variable.
b. To call immediate parent class constructor.
c. To invoke immediate superclass method.

17. Why do we use this keyword?

🅰 this keyword is a reference variable that refers to the current class object. It holds the reference to current class object or same class object.

There are six usages of Java this keyword. They are as follows:
1. this reference can be used to refer to the current class instance variable.
2. this keyword is used to call the non-static method of the current class.
3. this() can be used to invoke the current class constructor.

4. this keyword can be used as a parameter in the method call.
5. The keyword “this” can be used as a parameter in the constructor call.
6. It can also be used to return the object of the current class from the method.

18. Is it possible to use this() and super() both in same constructor?

🅰 No, Java does not allow using both super() and this() together in same constructor. As per Java specification, super() or this() must be the first statement in a constructor.

19. What are the differences between super and this keyword?

🅰 Go to this tutorial: Difference between super and this keyword

20. What is method overloading in Java?

🅰 When a class has more than one method having the same name but different in parameters, it is called method overloading in Java.