I think the thing you’re missing is that n and d are not members - they’re parameters.
In Scala, the entire class body is essentially a function. So since they are function parameters, they are visible everywhere inside that function. But they’re not visible anywhere outside of it, including in the companion object.
When you add val or var, then they become members. But by default, they’re just function parameters, and work as they do in any other function.