Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.
Exercise 1 of 3
Interact with live student objects and witness how each instance maintains its own private world in memory.
Experiment with how objects live in RAM
Observation: Notice how updating st1 moves its memory state, but st2 remains perfectly static. This is State Isolation.
Target: st1 (John)
Target: st2 (Sudhanshu)
Exercise 2 of 3
Construct the data members and methods for fundamental LLD entities: Points, Rectangles, and Students.
Structure the Point and Rectangle classes to handle coordinates and dimensions.
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.
Exercise 3 of 3
Predict the output of complex reference manipulation and swap scenarios. Master how variables point to objects on the heap.
Student s1 = new Student(); s1.age = 10; s1.name = "A"; Student s2 = s1; s2.age = 20; s2.name = "B"; s1.display();
Predict the output of the final line:
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.
Practical exercises to master the concepts.
Create a Smartphone class. Instantiate two phones. Drain battery from one and prove the other remains at 100%.