As I'm getting to know about inheritance in C++, one thing that has stuck in my mind is using public keyword before class_name as in-

class Derived: public Base {}

What I wonder is that why do we need to make a class public that's already outside the main function?
Isn't something global?I understand making class members public, but why to make the whole class public?

What's there behind the scene that I need to know?

A Global variable is defined outside all functions.The scope of a global variable is the whole program and It can be used and changed at any part of the program after its declaration.
By making class and class member Public you can use it in any part of program using inheritance.when your variable is global you can use it directly without use of inheritance but in some scenario you don't want to make variable is accessable to all function or method that's why we use public .
hope it helps!