Interview questions 2 Flashcards
What is a data structure?
A storage format that defines the way data is stored, organized, and manipulated.
What is an array?
Collection of items of the same type in contiguous memory locations.
What is a linked list?
A linear data structure in which elements are not necessarily stored contiguously. Sequence of nodes, each one pointing to the next in a chain-like structure.
What is a binary tree?
An extension of the linked list where each node has at most 2 children.
What is recursion?
A function calling itself based on a terminating condition.
What is OOP?
A paradigm that provides concepts such as objects, classes, and inheritance.
What is an object in OOP?
A real-world entity that has a particular state and behavior. It is an instance of a class.
What is a class in OOP?
A logical entity that defines the blueprint from which an object can be created or instantiated.
What is inheritance & its benefits?
An object gaining all the properties & behaviors of a parent object. Provides code reusability.
What is polymorphism?
A concept that allows a variable, function, or object to take on multiple forms. This happens when many classes are related to each other by inheritance.
Inheritance vs polymorphism.
While inheritance allows us to inherit attributes & methods from another class, polymorphism uses those methods to perform different tasks.
Example of polymorphism.
class Animal
public void animalSound()
System.out.println(“The animal makes a sound”);
class Pig extends Animal
public void animalSound() {
System.out.println(“The pig says: wee wee”);
class Dog extends Animal
public void animalSound() {
System.out.println(“The dog says: bow wow”);
What is overloading?
Method Overloading allows different methods to have the same name, but different signatures where the signature can differ by the number of input parameters or type of input parameters, or a mixture of both.
What is overriding?
Same method (with same parameters & type) exists in a child & parent class. The child is given priority.
What is an abstract class?
A class you cannot instantiate.