Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Doubt on Chapter 4 #7 question by OCA Jeanne Boyarsky and Scott Selikoff  RSS feed

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line numbers in main generate compile error?



A.None,the code compiles fine
B.Line 23
C.Line 24
D.Line 25
E.Line 26
F.Line 27

Answers are B,C,D,F

My doubt is in how will the compiler identify room as an object of Classroom while accessing roomNumber,floor,teacherName ,when it has failed to instantiate Classroom object room ? Can anybody please explain how Compiler thinks in this particular example?

Thanks,
Veena
 
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Veena Pointi wrote:. . . Answers are B,C,D,F . . .

Please tell us what the “correct” and “incorrect” answers are.
 
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Veena Pointi
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote: Please tell us what the “correct” and “incorrect” answers are.



Sorry.Edited the post to include answers.
 
Veena Pointi
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote: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.



Nice explanation. So is it right to understand that compiler sees code the way we see except for RunTimeExceptions ?
 
Campbell Ritchie
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is line 5 (answer B)? I can't see anything wrong with it.
 
Veena Pointi
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am so sorry .My mistake in mapping line numbers from book .It is actually line 23.
 
Something must be done about this. Let's start by reading this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!