Access Modifiers

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

1

Exercise 1 of 2

Inheritance: Point Dimensions

Design a 2D and 3D coordinate system using inheritance, access modifiers, and method overriding.

The Point & ThreedPoint Architecture

You are building a geometry library. Point handles 2D coordinates, while ThreedPoint adds the Z-axis. Assign the correct **Access Modifiers** to satisfy the requirements.

x field in Point
y field in Point
display() in Point
z field in ThreedPoint
display() in ThreedPoint

Assign all modifiers to see results

2

Exercise 2 of 2

Inheritnance: The Reference Quiz

Predict the output of various reference vs. instance combinations. Master shadowing, hiding, and overriding.

Child reference, Child instance

// Analyzing:
C obj = new C();

obj.d1;
obj.d;
obj.fun1();
obj.fun();
obj.sfun;

"Variables hide based on the Left Side (Ref). Methods override based on the Right Side (Heap). Static follows the Left Side."

obj.d1
obj.d
obj.fun1()
obj.fun()
obj.sfun()

Reference vs. Instance Simulation

Hands-on Labs

Practical exercises to master the concepts.

Practical Lab
Access Control

Access Level Challenge

Create a SecurityGuard class. Use private for the password, protected for clearanceLevel, and public for name.

Try implementing this on your own first!
Practice: Access Modifiers — Interactive Exercises | Durgesh Rai