Latest Update 100% Pass
What is the difference between an `ArrayList` and an array in Java?
✔✔ An `ArrayList` is a resizable data structure that can grow and shrink dynamically, whereas
an array has a fixed size. Additionally, `ArrayList` provides methods for manipulating the list,
such as adding, removing, and searching for elements.
What is inheritance, and how does it work in Java?
✔✔ Inheritance allows a new class (subclass) to inherit properties and methods from an existing
class (superclass). The subclass can reuse, modify, or extend the behavior of the superclass,
promoting code reuse and hierarchy.
How does method overloading differ from method overriding in Java?
✔✔ Method overloading occurs when multiple methods in a class have the same name but
different parameters. Method overriding occurs when a subclass provides a specific
implementation of a method already defined in its superclass.
1
, What is the purpose of the `static` keyword in Java?
✔✔ The `static` keyword indicates that a method or variable belongs to the class rather than to
any specific instance of the class. Static methods can be called without creating an object, and
static variables are shared among all instances of the class.
How do you implement encapsulation in Java?
✔✔ Encapsulation is implemented by declaring class variables as `private` and providing
`public` getter and setter methods to access and modify those variables. This restricts direct
access to the data, protecting it from unauthorized or unintended changes.
What is the difference between the `==` operator and the `.equals()` method in Java?
✔✔ The `==` operator checks for reference equality, meaning it compares whether two object
references point to the same memory location. The `.equals()` method checks for content
equality, meaning it compares the actual data inside the objects.
2