• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80226
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28364
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80226
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is line 5 (answer B)? I can't see anything wrong with it.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am so sorry .My mistake in mapping line numbers from book .It is actually line 23.
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic