Skip to content

PUBLIC QUESTION PREVIEW

CS Fundamentals interview questions

OOPs, OS, Networking, DBMS — concepts every engineer must know cold.

Showing 12 of 32 source questions. Sample answers are study material, not employer-specific hiring guidance.

How to work through this preview

Attempt each question before reading its answer. For a concept, give a definition and a concrete example. For code, state constraints, walk through a small input, and check complexity. For design, separate requirements from assumptions and explain failure handling. Use real situations for behavioral answers.

QUESTION 1 / easy / conceptual

What are the four pillars of OOP? Give a real-world example for each.

Sample answer

1. Encapsulation: Bundling data + methods, hiding internals. Bank account — balance is private, only exposed via deposit()/withdraw(). 2. Inheritance: Child class inherits parent. Vehicle → Car → ElectricCar. 3. Polymorphism: Same interface, different behaviour. Shape.draw() works differently for Circle vs Rectangle. 4. Abstraction: Expose what's necessary, hide implementation. A TV remote — you press "volume up" without knowing the electronics behind it.

Hints to guide your next attempt

  • AIPE: Abstraction, Inheritance, Polymorphism, Encapsulation

Source tags: oop / encapsulation / inheritance / polymorphism / abstraction

QUESTION 2 / easy / conceptual

What is a process vs. a thread? What is a context switch?

Sample answer

Process: independent program with its own memory space, file handles, and state. Isolated — crash in one doesn't affect another. Thread: unit of execution within a process. Shares the process's memory and resources. Lighter to create than a process. Context switch: when the OS pauses one process/thread and resumes another, saving all CPU registers and state. Expensive because it invalidates CPU caches. Threads context-switch faster than processes since they share memory.

Hints to guide your next attempt

  • Processes have separate memory; threads share memory
  • Context switch = saving and restoring CPU state

Source tags: os / process / thread / context-switch

QUESTION 3 / medium / conceptual

What is a deadlock? What are the four necessary conditions for it to occur?

Sample answer

Deadlock: two or more threads wait forever for resources held by each other. Four Coffman conditions (all must hold): 1. Mutual Exclusion — resource can only be held by one thread. 2. Hold and Wait — thread holds a resource while waiting for another. 3. No Preemption — resources can't be forcibly taken away. 4. Circular Wait — Thread A waits for B's resource, B waits for A's. Prevention: break any one condition — e.g., enforce a global lock ordering to eliminate circular wait.

Hints to guide your next attempt

  • Coffman conditions — all four must hold simultaneously

Source tags: os / deadlock / concurrency / coffman

QUESTION 4 / easy / conceptual

Explain the TCP 3-way handshake. Why is it needed?

Supplied choices

  1. SYN → ACK → SYN-ACK
  2. SYN → SYN-ACK → ACK
  3. ACK → SYN → SYN-ACK
  4. SYN → SYN → ACK

Source answer choice: B. SYN → SYN-ACK → ACK

Sample answer

1. Client → Server: SYN (I want to connect, my seq = x) 2. Server → Client: SYN-ACK (OK, my seq = y, I acknowledge your seq x+1) 3. Client → Server: ACK (I acknowledge your seq y+1) Why needed: TCP is reliable and ordered. The handshake synchronizes initial sequence numbers on both sides and confirms bidirectional communication works before any data is sent. Without it, you couldn't detect packet loss, reordering, or a server that's not actually listening.

Hints to guide your next attempt

  • SYN, SYN-ACK, ACK
  • Establishes that both sides can send and receive

Source tags: networking / tcp / handshake / protocol

QUESTION 5 / medium / conceptual

What is database normalization? Explain 1NF, 2NF, and 3NF with a simple example.

Sample answer

Normalization reduces data redundancy and improves integrity. 1NF: Each column holds atomic values (no lists, no repeating groups). A "courses" column with "Math, Science" violates 1NF — split into rows. 2NF: Must be 1NF + no partial dependencies (every non-key column depends on the whole primary key, not just part of it). If PK is (studentId, courseId), and studentName depends only on studentId — that's a partial dependency. Move studentName to a Students table. 3NF: Must be 2NF + no transitive dependencies (non-key column depending on another non-key column). If zipCode determines city, and city is in the table — that's transitive. Move to a ZipCodes table.

Hints to guide your next attempt

  • Each normal form fixes a specific type of redundancy
  • Think about a student-course table with repeated data

Source tags: database / normalization / 1nf / 2nf / 3nf

QUESTION 6 / easy / conceptual

What is the difference between stack and heap memory? What causes a stack overflow?

Sample answer

Stack: fixed-size memory for function call frames, local variables, return addresses. LIFO. Fast allocation. Automatically managed. Heap: dynamic memory for objects allocated at runtime (malloc, new). Slower, must be explicitly freed (or GC'd). Much larger. Stack overflow: each function call pushes a frame on the stack. Infinite recursion (or very deep recursion) keeps pushing frames until the stack is exhausted → stack overflow. The fix is either iteration or increasing stack size (as a last resort).

Hints to guide your next attempt

  • Stack is LIFO, heap is dynamic allocation
  • Recursion uses stack frames

Source tags: memory / stack / heap / stack-overflow

QUESTION 7 / medium / conceptual

What is the SOLID principle? Explain each with one line.

Sample answer

S — Single Responsibility: A class should have only one reason to change. O — Open/Closed: Open for extension, closed for modification. Add behaviour via new classes, not editing existing ones. L — Liskov Substitution: Subtypes must be substitutable for their base types without breaking the program. I — Interface Segregation: Don't force classes to implement interfaces they don't use. Prefer small, specific interfaces. D — Dependency Inversion: Depend on abstractions (interfaces), not concrete implementations.

Hints to guide your next attempt

  • S-O-L-I-D — five design principles by Robert Martin

Source tags: solid / design-principles / oop / architecture

QUESTION 8 / easy / conceptual

What is the difference between a class and an object? How does instantiation work?

Sample answer

Class: a blueprint/template that defines properties (fields) and behaviours (methods). It exists only in code — no memory is allocated for a class itself. Object: a concrete instance of a class, allocated in memory at runtime. Each object has its own copy of instance fields. Instantiation: the new keyword allocates heap memory, initialises fields to defaults, then calls the constructor to set initial state. class Car { string Brand; int Speed; void Accelerate() {} } // class — blueprint Car myCar = new Car(); // object — myCar holds a reference to the heap allocation One class, many objects: Car car1 = new Car(); Car car2 = new Car(); — two independent instances, same blueprint.

Hints to guide your next attempt

  • Class = blueprint, object = instance in memory
  • new allocates heap memory and calls the constructor

Source tags: oop / class / object / instantiation

QUESTION 9 / easy / conceptual

What is a constructor? Explain default, parameterized, and copy constructors.

Sample answer

Constructor: a special method called automatically when an object is created. Same name as the class, no return type. Its job: initialise the object to a valid state. Default constructor: no parameters. If you define none, the compiler generates one. Sets fields to defaults (0, null, false). Parameterized constructor: accepts arguments so callers set initial state. Replaces the compiler-generated default unless you explicitly keep both. Copy constructor (C# — manual): public Person(Person other) { Name = other.Name; Age = other.Age; } Constructor chaining with this(): public Car() : this("Unknown", 0) {} public Car(string brand, int speed) { Brand = brand; Speed = speed; } In inheritance, base() calls the parent constructor: public SportsCar(string brand) : base(brand, 200) {}

Hints to guide your next attempt

  • Constructor has no return type, same name as class
  • In C#: copy constructor is not built-in — you write it manually

Source tags: oop / constructor / copy-constructor / constructor-chaining

QUESTION 10 / easy / conceptual

Explain encapsulation beyond "hiding data". What practical problems does it solve?

Sample answer

Encapsulation = bundling data + the methods that operate on it inside a class, controlling external access via access modifiers. Practical problems it solves: 1. Protecting invariants: a BankAccount balance must never go negative. Without encapsulation, anyone writes account.balance = -9999. With it, only Withdraw() can change balance, and it validates first. 2. Controlled mutation: properties with getters/setters let you add validation later without breaking callers. 3. Change isolation: internal representation can change (store balance as decimal instead of double) without breaking any external code. 4. Reduces coupling: callers depend only on the public API, not the internal structure. Swap internals freely. Rule of thumb: make everything private by default, expose only what you must. Every public field is a contract you can never easily break.

Hints to guide your next attempt

  • Think: what breaks without encapsulation?
  • Invariants, controlled mutation, change isolation

Source tags: oop / encapsulation / access-modifiers / invariants

QUESTION 11 / easy / conceptual

What are access modifiers? Explain public, private, protected, and internal in C#.

Sample answer

Access modifiers control who can see a member. private: accessible only within the same class. Default for class members. Use for implementation details. protected: accessible within the class and all derived classes. Use when subclasses need it but external code should not. internal: accessible within the same assembly (.dll/.exe). Useful for sharing across classes in the same project without exposing to outside packages. public: accessible from anywhere. The minimum surface area needed for your API. protected internal (C#): accessible within the assembly OR any derived class outside the assembly. Union of both. private protected (C#): accessible only within the same class or derived classes in the same assembly. Intersection. Design principle: start private, widen only when forced. Each level of widening is a contract you must maintain.

Hints to guide your next attempt

  • C# has 6 access modifiers
  • Default for class members is private

Source tags: oop / access-modifiers / encapsulation / csharp

QUESTION 12 / easy / conceptual

What are the types of inheritance? What does C# support?

Sample answer

Single inheritance: class B extends class A. One parent. C# supports this. Multi-level inheritance: A -> B -> C. B inherits A, C inherits B. A chain. C# supports this. Hierarchical inheritance: one parent, multiple children. A -> B, A -> C. C# supports this. Multiple inheritance (classes): one class directly inherits from two classes. C# does NOT support this for classes — it prevents the Diamond Problem. Java also disallows it. Multiple inheritance via interfaces: C# and Java DO support implementing multiple interfaces. This is how "multiple inheritance of contracts" is safely achieved. Diamond Problem: if B and C both inherit A and override method M(), and D inherits both B and C — which M() does D call? C# sidesteps this by disallowing multiple class inheritance.

Hints to guide your next attempt

  • C# supports single class inheritance but multiple interface implementation
  • Multi-level vs multiple are different things

Source tags: oop / inheritance / multiple-inheritance / diamond-problem

Check understanding, not recognition

  • Can you explain the answer without reading it?
  • Can you show when the approach fails or needs a different assumption?
  • Can you connect the concept to a real project, task, or decision you have made?
  • Can you distinguish a simplified interview example from a production requirement?

A LITTLE MORE CLARITY

Frequently asked questions

How many CS Fundamentals questions are shown here?

This public preview shows 12 questions with the supplied answers from the app's 32-question CS Fundamentals bank. Full interactive practice requires signing in.

Should I memorize the sample answers?

Use them as reference explanations, not a script or a guarantee of technical correctness for every environment. Explain your assumptions, validate code against your language and version, and discuss trade-offs. Behavioral answers should be built from your own experience.

What do hints and solution steps mean?

Hints identify ideas to consider before reading the answer. When the source question includes steps, they are shown as a separate walkthrough. Example capacities and design targets in a solution are assumptions for that exercise, not real system statistics.

BUILD YOUR NEXT OPPORTUNITY

Practice CS Fundamentals actively.

Sign in to use the full topic bank and interactive practice workspace.

Open Topic Practice