All Core Java Interview Questions & Answers for Selenium Automation - Real-Time Guide
All Core Java Interview Questions & Answers for Selenium Automation - Real-Time Guide
1. OOPs Concepts
Q1: What is Inheritance in Java?
A: Inheritance is a mechanism where one class acquires the properties (fields) and behaviors (methods) of another
class. Useful for code reusability.
class Animal {
void eat() { System.out.println("eating..."); }
class Dog extends Animal {
void bark() { System.out.println("barking..."); }
Q2: What is Polymorphism?
A: The ability of an object to take many forms. It is of two types:
- Compile-time (Method Overloading)
- Runtime (Method Overriding)
Q3: What is Abstraction?
A: Hiding internal implementation and showing only the functionality. Achieved using abstract classes and interfaces.
Q4: What is Encapsulation?
A: Wrapping data and code into a single unit (class), usually by making fields private and providing public
getters/setters.
2. Interface vs Abstract Class
Q5: Difference between Interface and Abstract Class?
A:
Feature | Interface | Abstract Class
-------------------- | ------------------------------ | --------------
Multiple Inheritance | Yes | No
Page 1
All Core Java Interview Questions & Answers for Selenium Automation - Real-Time Guide
Constructors | No | Yes
Access Modifiers | Only public | Can use all
Implementation | Only abstract methods (Java 7) | Can have both
3. Method Overloading vs Overriding
Q6: What is Method Overloading?
A: Same method name with different parameters.
Q7: What is Method Overriding?
A: Redefining a method of the parent class in the child class.
... (continues for all 28 questions as shown above)
Page 2