Veena Pointi wrote:My doubt is in how will the compiler identify room as an object of Classroom while accessing roomNumber,floor,teacherName
It does that because the variable
room is declared to be of type
Classroom. That happens here:
when it has failed to instantiate Classroom object room ? Can anybody please explain how Compiler thinks in this particular example?
The compiler doesn't "fail to instantiate" anything. It doesn't even try to instantiate objects -- that happens at run time. As I said, the compiler sees that
room is declared to be of type
Classroom. You can see that too, without having to execute any code.