• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Sybex 1Z0-815, Chapter 7, Review question 10

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I think this question contains an error. The answer states that the code compiles fine, but I think since class Rope does not have a public no-args constructor, the "new Rope()" statement on line 6 should not compile. Therefore, the correct answer is E instead of B.

Some code I wrote to test this theory.

class Animal


Class test


The code above won't compile unless I make the Animal's no-args constructor public.
 
Dimitri Nguyen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, if I was correct, then review question #12 also has the same problem.
 
Marshal
Posts: 74050
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please confirm that is the Boyarsky and Selikoff book. Please supply full details of the question because most of us don't have access to that book.
 
Dimitri Nguyen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please confirm that is the Boyarsky and Selikoff book. Please supply full details of the question because most of us don't have access to that book.



Hi Campbell,

The full title to the book is
OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 1st Edition, Kindle Edition
by Jeanne Boyarsky, Scott Selikoff

I was not sure if I can post the code in the book due to copyright concerns, but I guess it's ok since the author tells us to report the issues here:

Chapter 7, review question 10:



Answer choices:


Chapter 7, review question 12:



Answer choices:

 
Campbell Ritchie
Marshal
Posts: 74050
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the full question. Please don't copy the line numbers because the code tags add line numbers automatically. I hope the original code wasn't formatted so badly; I have tried to correct that.

Dimitri Nguyen wrote:. . . copyright concerns . . .

I think the amount you have posted would count as “fair comment” about the book, which is permissible.

Chapter 7, review question 10:





Answer choices:


Chapter 7, review question 12:





Answer choices:

The answers should be,“swing swing 10” and, ”8”.

. . . class Rope does not have a public no-args constructor, . . .

Of course it does; every class has a constructor. Look at how many constructors have been written and work out what sort of constructor the Rope.class file will have. Also work out why the 0 in line 6 isn't displayed.

 
Dimitri Nguyen
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Of course it does; every class has a constructor. Look at how many constructors have been written and work out what sort of constructor the Rope.class file will have. Also work out why the 0 in line 6 isn't displayed.



Hello, I was talking about the fact that the constructor of class Rope is not public. The one that the compiler gives only has package access. So if you want to instantiate Rope outside of the package rope, then Rope's constructor must be public.

I also tested my theory with the code I posted in my first post. The SO links below also seem to agree with me theory.

https://stackoverflow.com/questions/13541386/default-access-modifier-for-a-java-constructor/13541412
https://stackoverflow.com/questions/22007143/whats-the-access-modifier-of-the-default-constructor-in-java
 
Campbell Ritchie
Marshal
Posts: 74050
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those SO links both clearly tell you why the default constructor in Rope has public access. I ran the code and it compiled normally. Both version of Rope have public access, in which case the default constructors will also have public access.
 
Dimitri Nguyen
Greenhorn
Posts: 20
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Those SO links both clearly tell you why the default constructor in Rope has public access. I ran the code and it compiled normally. Both version of Rope have public access, in which case the default constructors will also have public access.



Sorry, in one of my test classes, I had another constructor in there, so the default constructor was not provided, hence it caused me some confusion. If anything, at least I learned about the default access modifiers for no-arg constructors (and also applicable to inner classes). Thank you for your support.
 
Campbell Ritchie
Marshal
Posts: 74050
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dimitri Nguyen wrote:. . .  in one of my test classes, I had another constructor . . .

That shows what confusion you can get into if your code isn't exactly the same as what you ask about.

Thank you for your support.

That's a pleasure
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic