{"id":2085,"date":"2017-03-26T13:12:41","date_gmt":"2017-03-26T13:12:41","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2085"},"modified":"2017-03-26T13:17:36","modified_gmt":"2017-03-26T13:17:36","slug":"can-abstract-class-can-have-private-methods-and-constructors","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/can-abstract-class-can-have-private-methods-and-constructors\/","title":{"rendered":"Can Abstract class can have Private Methods and Constructors"},"content":{"rendered":"<p><strong>Yes<\/strong>.You can use any kind of method in an abstract class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic abstract class AbstractDAO{\r\n\r\npublic void save(){\r\n  validate();\r\n  \/\/save\r\n}\r\n  private void validate(){ \/\/ we are hiding this method\r\n  }\r\n}\r\n<\/pre>\n<p><strong>Private Constructors<\/strong><br \/>\nIf Private constructor is the only constructor of the class, then the reason is clear: to prevent subclassing. Some classes serve only as holders for static fields\/methods and do not want to be either instantiated or subclassed. Note that the abstract modifier is in this case redundant\u2014with or without it there would be no instantiation possible. The abstract modifier is also bad practice because it sends wrong signals to the class&#8217;s clients. The class should in fact have been final.<\/p>\n<p><strong>Abstract Class with Private Constructor is same as Final Class. Both serves the same purpose.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes.You can use any kind of method in an abstract class public abstract class AbstractDAO{ public void save(){ validate(); \/\/save } private void validate(){ \/\/ we are hiding this method } } Private Constructors If Private constructor is the only constructor of the class, then the reason is clear: to prevent subclassing. Some classes serve&hellip; <a href=\"https:\/\/codethataint.com\/blog\/can-abstract-class-can-have-private-methods-and-constructors\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[97],"tags":[],"class_list":["post-2085","post","type-post","status-publish","format-standard","hentry","category-abstract"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2085"}],"version-history":[{"count":3,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2085\/revisions"}],"predecessor-version":[{"id":2088,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2085\/revisions\/2088"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}