When I call as instance method of a class as follows :
object_name.function_name(); how the compiler knows that the “function_name” has to be called for that “object_name” behind the scenes ?
When I call as instance method of a class as follows : object_name.function_name(); how
Share
This is determined by the compiler as it reads your code. Java has a syntax which defines the rules and grammar of the language. Java’s particular syntax dictates that object references can be followed by a dot and then a method name.
All languages (not just programming languages) have similar rules. Your brain is compiling the sentence you are reading now based on the syntax of the English language. The rules of the language are what makes it possible for the language to be understood. By defining rules about the meaning of expressions, we are able to communicate. Programming languages are no different!