• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access Modifiers Question  RSS feed

 
Ioanna Katsanou
Ranch Hand
Posts: 124
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, during studying I faced this question:

Given the following my.school.ClassRoom and my.city.School class definitions, which
line numbers in main() generate a compiler error? (Choose all that apply)




A. None, the code compiles fine.
B. Line 5
C. Line 6
D. Line 7
E. Line 8
F. Line 9



The correct answer is B,D,F,C

I inderstand that:

B causes compile error because globalKey  access set to default meaning that only the classes in the same package can view it
D causes compile error because roomNumberis is private
F causes compile error because teacherName is protected and School does not extend ClassRoom

I cannot understand why C causes compile error.
Classroom room = new Classroom(101, ""Mrs. Anderson");
It just creates a new instance of the class.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us where such questions come from, to avoid copyright problems and at allow us to assess the original.
Please look at the access modifier for the Classroom constructor.
 
Ioanna Katsanou
Ranch Hand
Posts: 124
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This comes from SYBEX book.

Ok my mistake, I didn't notice that the constructor has default access modifier, so it is only available in the same package

thanks
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure to help Which Sybex book, and which page, please?
 
Ioanna Katsanou
Ranch Hand
Posts: 124
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:My pleasure to help Which Sybex book, and which page, please?



OCA: Oracle®
Certified Associate Java®
SE 8 Programmer I
Study Guide
Exam 1Z0-808

page 220
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiosity, but do these questions really have no indentation in them?
 
Liutauras Vilda
Sheriff
Posts: 4913
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ioanna Katsanou wrote:

Such line of code shouldn't compile, but check if you copied it right.

I have copied this topic to our OCA certification topic too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!