{"id":6122,"date":"2015-01-06T20:20:58","date_gmt":"2015-01-07T04:20:58","guid":{"rendered":"http:\/\/unwisdom.org\/chadspace\/?p=6122"},"modified":"2017-11-16T03:48:53","modified_gmt":"2017-11-16T11:48:53","slug":"cross-purposes","status":"publish","type":"post","link":"http:\/\/unwisdom.org\/chadspace\/?p=6122","title":{"rendered":"Cross Purposes"},"content":{"rendered":"<p>As I prepare to test for my Java certifications, I am frequently reminded that patience is not always a virtue.  See below:<\/p>\n<pre><code>03. class Alpha {\r\n04.   static String s = \" \";\r\n05.   protected Alpha() {\r\n06.     s += \"alpha \";\r\n07.   }\r\n08. }\r\n09. class SubAlpha extends Alpha {\r\n10.     private SubAlpha() {\r\n11.       s += \"sub \";\r\n12.     }\r\n13. }\r\n14. public class SubSubAlpha extends Alpha {\r\n15.    private SubSubAlpha() {\r\n16.      s += \"subsub \";\r\n17.    }\r\n18.    public static void main( String[] args ) {\r\n19.      new SubSubAlpha();\r\n20.      System.out.println( s );\r\n21.    }\r\n22. }\r\n\r\nWhat is the result?\r\n<strong>A.<\/strong>  subsub\r\n<strong>B.<\/strong>  sub subsub\r\n<strong>C.<\/strong>  alpha subsub\r\n<strong>D.<\/strong>  alpha sub subsub\r\n<strong>E.<\/strong>  Compilation fails\r\n<strong>F.<\/strong>  An exception is thrown at runtime\r\n\r\nAnswer:  <strong>C<\/strong> is correct.  Watch out, because SubSubAlpha extends\r\nAlpha!  Since the code doesn't attempt to make a SubAlpha, the\r\nprivate constructor in SubAlpha is okay.\r\n<\/code><\/pre>\n<p>Yes, I must concede that I got this particular question wrong.  And you know what?  I&#8217;m not going to lose a bit of sleep over it.  While I regularly use <code>private<\/code> constructors in my classes, I have yet to use them in tandem with any descendents of said classes.  If I was willing (or perhaps able) to spend more than two or three minutes on the problem during the exam, the <code>private<\/code> constructor would have received additional scrutiny and led me along a path to the correct answer.<\/p>\n<p>The point is this:  I could have made the investment of an hour and I <em>never<\/em> would have noticed the <code>SubSubAlpha extends Alpha<\/code> bullshit, which serves as a nearly instantaneous escape hatch for the inexperienced and superficially intelligent.  People who write obnubilated code and excel at these types of questions are the kind you want working for your competitors, not with you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I prepare to test for my Java certifications, I am frequently reminded that patience is not always a virtue. See below: 03. class Alpha { 04. static String s = &#8221; &#8220;; 05. protected Alpha() { 06. s += &hellip; <a href=\"http:\/\/unwisdom.org\/chadspace\/?p=6122\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[125],"tags":[73],"class_list":["post-6122","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-java"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3DQCb-1AK","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/posts\/6122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6122"}],"version-history":[{"count":45,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/posts\/6122\/revisions"}],"predecessor-version":[{"id":6171,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=\/wp\/v2\/posts\/6122\/revisions\/6171"}],"wp:attachment":[{"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6122"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/unwisdom.org\/chadspace\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}