{"id":214,"date":"2025-06-24T07:09:49","date_gmt":"2025-06-24T07:09:49","guid":{"rendered":"https:\/\/thetestdata.com\/blog\/?p=214"},"modified":"2025-07-16T10:28:06","modified_gmt":"2025-07-16T10:28:06","slug":"what-is-an-abstract-modifier","status":"publish","type":"post","link":"https:\/\/thetestdata.com\/blog\/what-is-an-abstract-modifier\/","title":{"rendered":"What is an abstract modifier?"},"content":{"rendered":"\n<p><code>The abstract modifier is used to declare something that is <em>incomplete<\/em> and meant to be extended or implemented by other classes. You can apply it to both classes and methods, and here\u2019s what it means in each case<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\ud83d\udd39 Abstract Class<\/p>\n\n\n\n<p>An abstract class is a class that <strong>cannot be instantiated<\/strong> on its own\u2014it\u2019s like a blueprint for other classes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"985\" height=\"198\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-4.png\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-4.png 985w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-4-300x60.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-4-768x154.png 768w\" sizes=\"auto, (max-width: 985px) 100vw, 985px\" \/><\/figure>\n\n\n\n<p>You can&#8217;t do <code>new Animal()<\/code>, but you <em>can<\/em> create subclasses that extend it and provide implementations for its abstract methods.<\/p>\n\n\n\n<p>\ud83d\udd39 Abstract Method<\/p>\n\n\n\n<p>An abstract method is a method <strong>without a body<\/strong>, declared in an abstract class. Subclasses are <em>required<\/em> to provide an implementation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"196\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-5.png\" alt=\"\" class=\"wp-image-216\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-5.png 972w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-5-300x60.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-5-768x155.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p>So, <code>abstract<\/code> is Java&#8217;s way of saying, <em>&#8220;Here&#8217;s the framework\u2014now you fill in the details.&#8221;<\/em><\/p>\n\n\n\n<p>Example :<\/p>\n\n\n\n<p>\/\/ Abstract class<br>abstract class Animal {<br>\/\/ Abstract method (no body)<br>abstract void sound();<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Regular method\nvoid breathe() {\n    System.out.println(\"All animals breathe.\");\n}<\/code><\/pre>\n\n\n\n<p>}<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\/\/ Subclass of Animal<br>class Dog extends Animal {<br>\/\/ Implementing the abstract method<br>void sound() {<br>System.out.println(&#8220;Dog says: Woof!&#8221;);<br>}<br>}<\/p>\n\n\n\n<p>public class Main {<br>public static void main(String[] args) {<br>Dog myDog = new Dog(); \/\/ Create a Dog object<br>myDog.sound(); \/\/ Calls the implemented method<br>myDog.breathe(); \/\/ Calls the regular method<br>}<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn what the abstract modifier means in Java. Discover how it defines abstract classes and methods to enforce structure and enable flexible subclassing.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[17],"tags":[],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-java-interview-questions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":3,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":455,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions\/455"}],"wp:attachment":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}