DEV Community

Cover image for Common telephonic interview questions - Section 1
NITESH TALIYAN
NITESH TALIYAN

Posted on

Common telephonic interview questions - Section 1

Several companies have a phone interview round where they ask you questions from your resume as well as some quick technical trivia questions. I have tried to compile a list of these questions. This should also be helpful to you if you are new to tech or would like to brush over some concepts.

Alt Text

1. Threads vs processes.

Process is an instance of a program, and Thread is a subset of the process. Both processes and threads are independent sequences of execution.
a). Threads (of the same process) run in shared memory space, while processes run in separate memory spaces. Hence, threads have their own stack(local variables) but share the same heap. Processes have separate stack and heap.

b). Threads can efficiently communicate by their shared memory. They can communicate using objects stored in the heap, where each thread has access to the same object at the same memory location. Processes use Inter-process Communication(IPC) and the OS has to be involved.
c). Threads take less time to create and terminate than processes because they consume fewer resources.

d). On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time. Hence threads are concurrent and not parallel per processor.
Alt Text

2. Data races:

A data race is a situation that occurs when multiple threads are running the same program and 2 or more threads get access to the same shared variable, at the same time. It leads to unpredictable outputs and can cause problems sometimes when the result is undesirable.

An example would be:

Ideal scenario: We want to increment the value of a variable whose initial value is 0, by 1, twice, and there are 2 threads doing this for us. The final result should be the value of the variable becomes 2.
Alt Text

If both threads read the original value and then rewrite it, the final result will be wrong, and this could be a major bug in our program.
Alt Text

Data races can be prevented by introducing a lock. That way, when one thread accesses the variable for updating its value, the variable’s access will be locked until that thread completes its operation. Hence, the other thread will have to “wait” and will not be able to access, read or change the variable's value before the first thread has finished updating it.

However, if the locks are not used carefully, they can lead to a deadlock.

3. Deadlock:

This is a situation where two or more threads are blocked permanently because they are waiting for each other. It causes the threads to hang, and could potentially lead the entire process to hang as well.

4. Four pillars of Object-Oriented Programming:

A Pie: Abstraction, Polymorphism, Inheritance, Encapsulation

A: Abstraction: Abstract classes and methods

i). You can remember what this means by the word “abstract” being a part of the word Abstraction.

ii). Used to hide complex details from the user, enabling user to use a program or implement more complex code on top, without worrying/knowing about the complexities involved with the current program.

iii). It is achieved by using abstract classes and methods.

iv). An abstract class is a class where we can declare abstract methods. An abstract method is a method without a body, with just the name and no implementation.

v). A classic example is an abstract Shape class with an abstract Area method. The children of this class (Circle, Triangle, etc) will have different ways of implementing this area method.

P: Polymorphism: Overriding and OverLoading

You can remember this by the word “poly” which means many in Greek. The same method can have “many” forms in different subclasses, by using overriding and overloading.

I: Inheritance: extends, parent and child class

You can remember this by keeping in mind that you inherit your parents’ features like hair and eye color etc. Similarly, inheritance is the process through which a child class receives or inherits the properties of its parent class.

The “extends” keyword is used to inherit the properties of any superclass ( parent class) by a child class ( subclass ). This helps in reusability, reduces code length and prevents the user from writing the same code over and over again.

E: Encapsulation: Getters and Setters

You can remember this by correlating the word encapsulation with “encapsulating” or wrapping up methods and variables together and hence hiding data.

It occurs when you declare variables as private and has getters and setters to provide access to them.

This helps in controlling what is stored in the fields of our class, having restrictions as well as making certain elements read-only or write-only.

5. Why do we need OOPS ( Object Oriented Programming System) ?

Object-Oriented Programming languages are the ones that use the concept of “objects” in programming. For answering this question, you can first say OOPs help in effective and easily manageable problem-solving. They make complex code more understandable and easy to maintain. You can then talk about the concepts of:

Object: Anything that represents a real-life entity

Class: Blueprint of an object

Methods: A few lines of code clumped together that perform some task, and they may or may not take in input and provide the desired output.

And then discuss the four pillars mentioned above with their benefits.

This should be enough to show that you have a thorough understanding of Object-Oriented programming.

That’s about it for part 1! Let me know if you find it helpful, and connect with me on my social sites for questions or blog topic suggestions. Thank you for reading!

Nitesh Taliyan

Latest comments (0)