Day 16 of 30
Day 16 of 30
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() {
}
}
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:
return a + b;
class Animal {
@Override
void sound() {
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() {
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 :
}
}
}
}
Method Overriding
Example :
class Animal {
void sound() {
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;
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);
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.
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
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.
driver.quit();
}
}
}
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.
1. Sprint planning
3. Sprint Review
4. Sprint Retrospective
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.