Blueprints & Objects

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

1

Exercise 1 of 3

RAM Isolation Lab: st1 vs st2

Interact with live student objects and witness how each instance maintains its own private world in memory.

Memory & Instance Isolation

Experiment with how objects live in RAM

Heap Memory
st1 (ref: 0x7af4)
John
Current Batch
March-2024
PSP Score
st2 (ref: 0x9bf4)
Sudhanshu
Current Batch
March-2024
PSP Score

Observation: Notice how updating st1 moves its memory state, but st2 remains perfectly static. This is State Isolation.

Action Console

Target: st1 (John)

Target: st2 (Sudhanshu)

Runtime Logs
Waiting for connection...
2

Exercise 2 of 3

Class Blueprints: Building the Anatomy

Construct the data members and methods for fundamental LLD entities: Points, Rectangles, and Students.

Task 1: Point & Rectangle

Structure the Point and Rectangle classes to handle coordinates and dimensions.

  • Point must have int x and int y
  • Rectangle must have Point topLeft, int height, and int width
  • Rectangle.getArea() -> height * width
  • Rectangle.getBottomRight() -> new Point(topLeft.x + width, topLeft.y - height)
class Point {
  int x;
  int y;
}

class Rectangle {
  Point topLeft;
  int height;
  int width;

  int getArea() {
    return ;
  }

  Point getBottomRight() {
    return new Point(, );
  }
}

💡 Member Variables define the state (data), while Methods define the behavior (actions). In LLD, getting the relationship (like Rectangle having a Point) is just as important as the logic.

3

Exercise 3 of 3

Memory Maze: Reference vs Instance

Predict the output of complex reference manipulation and swap scenarios. Master how variables point to objects on the heap.

Puzzle 1: The Simple Assignment

Puzzle 1 of 4
Student s1 = new Student();
s1.age = 10;
s1.name = "A";

Student s2 = s1;
s2.age = 20;
s2.name = "B";

s1.display();
Java / C++ / Python

Predict the output of the final line:

Memory State (Virtual)

Stack (References)
s1
addr_1
s2
addr_1
Heap (Instances)
addr_1
Student
name:"B"
age:20

Answer the puzzle
to reveal memory state

💡 Remember: In OOP languages, object variables contain addresses (pointers), not the objects themselves. Swapping the address doesn't change the object, and swapping values inside the object doesn't change the address.

Hands-on Labs

Practical exercises to master the concepts.

Practical Lab
Memory Isolation

Battery Isolation Test

Create a Smartphone class. Instantiate two phones. Drain battery from one and prove the other remains at 100%.

Try implementing this on your own first!
Practice: Blueprints & Objects — Interactive Exercises | Durgesh Rai