0% found this document useful (0 votes)
28 views11 pages

Day 16 of 30

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including encapsulation, inheritance, polymorphism, and abstraction, along with examples. It also covers Java-specific topics such as arrays, ArrayLists, collections, exceptions, alert handling in Selenium, dropdown selection, Agile ceremonies, and the differences between assertions and verifications in testing. Each section includes definitions, key points, and examples to illustrate the concepts discussed.

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)
28 views11 pages

Day 16 of 30

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including encapsulation, inheritance, polymorphism, and abstraction, along with examples. It also covers Java-specific topics such as arrays, ArrayLists, collections, exceptions, alert handling in Selenium, dropdown selection, Agile ceremonies, and the differences between assertions and verifications in testing. Each section includes definitions, key points, and examples to illustrate the concepts discussed.

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/ 11

On Weekend

DAY 16 : Automation Testing Interview Questions

/Junaid Aziz /Qasim Nazir


On Weekend

Q : What is Oops concept?


Ans :

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects,


which can contain data (attributes or properties) and methods (functions or behaviors). The main aim
of OOP is to organize and structure code in a way that makes it more modular, reusable, and easier to
maintain.

Core Principles of OOP:

Encapsulation:

 Definition: Bundling the data (variables) and the methods (functions) that operate on that data
into a single unit called a class.
 Key Idea: Hide the internal details and expose only what is necessary.
 Example: Using private fields and providing public getter and setter methods.

this.name = name;

Inheritance:

 Definition: The mechanism by which one class can acquire the properties and behaviors of
another class.
 Key Idea: Promotes code reuse and hierarchical classification.
 Example: A Car class can inherit from a Vehicle class

void drive() {

/Junaid Aziz /Qasim Nazir


On Weekend

}
}

Polymorphism:

 Definition: The ability of an object to take many forms. It allows one interface to be used for a
general class of actions.
 Key Types:
o Compile-time polymorphism (Method Overloading)
o Runtime polymorphism (Method Overriding)
 Example:

Method Overloading (Same method name, different parameters):

return a + b;

Method Overriding (Same method name, same parameters, but in a subclass):

class Animal {

@Override
void sound() {

/Junaid Aziz /Qasim Nazir


On Weekend

Abstraction:

 Definition: Hiding the implementation details and showing only the essential features of the
object.
 Key Idea: Focus on "what an object does" rather than "how it does it."
 Example: Using abstract classes or interfaces.

@Override
void draw() {

Q : Explain method overriding and method overloading with example.


Ans :

Method Overriding vs. Method Overloading

Both method overriding and method overloading are forms of polymorphism in Java, but they differ in
implementation and usage.

Method Overloading

 Definition: Method overloading allows a class to have multiple methods with the same name
but different parameter lists (number, type, or both).
 Key Points:
o Happens within the same class.
o Methods must have the same name but different arguments.
o Return type can be the same or different, but it alone is not sufficient for overloading.
o It is an example of compile-time polymorphism.

Example :

/Junaid Aziz /Qasim Nazir


On Weekend

// Method to add two doubles

}
}

public class Main {

System.out.println(calc.add(2, 3)); // Calls the first add method

}
}

Method Overriding

 Definition: Method overriding allows a subclass to provide a specific implementation for a


method that is already defined in its parent class.
 Key Points:
o Happens across two classes: a parent class and a child class.
o The overridden method must have the same name, return type, and parameters as
the method in the parent class.
o The overridden method in the subclass must have equal or more accessible visibility
than the parent method.
o It is an example of runtime polymorphism.

Example :

class Animal {

void sound() {

public class Main {

/Junaid Aziz /Qasim Nazir


On Weekend

animal.sound(); // Calls parent class method

Animal dog = new Dog(); // Polymorphic behavior


dog.sound();
}
}

Q : What is array and Arraylist


Ans :

Array
An array in Java is a fixed-size collection of elements of the same data type. It is part of the Java
language and is used for storing a group of elements in a contiguous memory location.

Features of Array :

 Fixed Size: The size is specified at the time of creation and cannot be changed.
 Homogeneous Data: All elements must be of the same type (e.g., all integers or all strings).
 Indexed: Each element is accessed using its index, starting from 0.
 Performance: Arrays are fast and memory-efficient but lack flexibility.

Example :

numbers[1] = 25;

/Junaid Aziz /Qasim Nazir


On Weekend

ArrayList

An ArrayList in Java is a part of the Java Collection Framework. It is a resizable array that can grow or
shrink in size dynamically. It is implemented in the java.util package.

Features of ArrayList :

 Dynamic Size: The size of an ArrayList grows automatically when elements are added and
shrinks when elements are removed.
 Heterogeneous Data: Technically, an ArrayList can store different types using generics, but
generally, elements are of the same type. 
 Methods: Provides built-in methods for common operations like adding, removing, searching,
and sorting elements.
 Slower: Slightly slower than arrays due to dynamic resizing and overhead of method calls.

Example :

numbers.add(10);
numbers.add(20);
numbers.add(30);

numbers.set(1, 25);

/Junaid Aziz /Qasim Nazir


On Weekend

Q : What are collections in java.


Ans :

Collections in Java
The Java Collections Framework (JCF) is a set of classes and interfaces that provide a standardized
way to store, manipulate, and retrieve groups of objects. Collections are used to manage dynamic
data structures such as lists, sets, queues, and maps.

Q : What is Stale Element exception? How to overcome it.


Ans :

The StaleElementReferenceException in Selenium occurs when a WebDriver tries to interact with a


web element that is no longer valid in the DOM (Document Object Model). This typically happens when
the DOM has been updated or refreshed, and the reference to the element is no longer accurate.

Common Scenarios That Cause StaleElementReferenceException

1. Page Refresh or Navigation:


o If the page is refreshed or navigated to a different page, the element reference
becomes stale.
2. DOM Update:
o If JavaScript or AJAX updates the DOM dynamically after the element is located, the
previously located element reference becomes invalid.
3. Element Removal and Re-Addition:
o If an element is removed and then re-added to the DOM (e.g., re-rendered or moved to
a different location).

How to Overcome StaleElementReferenceException

1. Re-locate the Element


2. Use WebDriverWait
3. Wrap the Interaction in a Retry Logic

Q : What are exceptions and How to handle exception?


Ans :

An exception is an event that disrupts the normal flow of a program's execution. It occurs during
runtime and represents an error or unexpected situation, such as dividing by zero, accessing an invalid
array index, or trying to open a file that doesn't exist.

Java provides several mechanisms for handling exceptions to ensure smooth execution and error
recovery:

Try-catch Block

Used to catch and handle exceptions.

/Junaid Aziz /Qasim Nazir


On Weekend

try {

Q : What is Alert ? Write down the code for a alert and print the data present on it and click on OK.

Ans :
An alert in Selenium refers to a small message box that pops up to provide information or ask for user
interaction. Alerts are typically JavaScript-based and can display warnings, confirmations, or prompts.

Types of Alerts in Selenium

1. Simple Alert: Displays a message with an "OK" button.


2. Confirmation Alert: Displays a message with "OK" and "Cancel" buttons.
3. Prompt Alert: Displays a message with a text input field, along with "OK" and "Cancel"
buttons.

public class AlertHandlingExample {

WebDriver driver = new ChromeDriver();

/Junaid Aziz /Qasim Nazir


On Weekend

driver.quit();
}
}
}

Q : How to select elements from the dropdowns?

Ans :

public class DropdownExample {

WebDriver driver = new ChromeDriver();

// Select an option by value

/Junaid Aziz /Qasim Nazir


On Weekend

}
}

Q : What are Agile ceremonies?


Ans :

Agile ceremonies, also called Agile events or rituals, are structured meetings or practices that help
teams work collaboratively, plan effectively, and deliver value consistently in an Agile framework. They
are an essential part of methodologies like Scrum and Kanban and ensure transparency, adaptability,
and continuous improvement in the development process.

Key Agile Ceremonies

1. Sprint planning

2. Daily Stand-Up (Daily Scrum)

3. Sprint Review

4. Sprint Retrospective

5. Backlog Refinement (Grooming)

Q : What is the difference between Assertion and verification?

Ans :

1. Assertion

 Definition:
An assertion is a statement that checks whether a specific condition is true or false during
test execution. If the condition is false, the test case fails immediately, and further steps in
that test case are not executed.

2. Verification

 Definition:
Verification checks whether a specific condition is true or false, but unlike assertions, it does
not stop the test execution even if the condition fails. Instead, it logs the failure and continues
with the remaining steps.

/Junaid Aziz /Qasim Nazir

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy