{"id":1039,"date":"2026-10-30T12:16:06","date_gmt":"2026-10-30T12:16:06","guid":{"rendered":"https:\/\/blog.debuggersspace.com\/?p=1039"},"modified":"2026-10-30T14:12:02","modified_gmt":"2026-10-30T14:12:02","slug":"what-is-the-difference-between-an-abstract-class-and-an-interface","status":"publish","type":"post","link":"https:\/\/blog.debuggersspace.com\/index.php\/2026\/10\/30\/what-is-the-difference-between-an-abstract-class-and-an-interface\/","title":{"rendered":"What is the difference between an abstract class and an interface?"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>1 Minute, 45 Second                <\/div>\n\n            <\/div>\n<p class=\"wp-block-paragraph\">Both let you define a type without a full implementation. The difference is what each can hold and how many a class can use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Side by side<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Abstract class            Interface\nInstance fields (state)  Yes                       No (only public static final constants)\nConstructors             Yes                       No\nMethod bodies            Yes, any                  default and static (Java 8+), private (Java 9+)\nAccess modifiers         Any                       Methods are public (except private helpers)\nA class can use          Only one (extends)        Many (implements)\nRepresents               \"is-a\" with shared code   A capability or contract (\"can do\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface Notifier {            \/\/ a capability\n    void send(String to, String msg);\n    default void sendAll(List&lt;String&gt; to, String msg) { to.forEach(t -&gt; send(t, msg)); }\n}\n\npublic abstract class BaseReport {     \/\/ shared state and steps\n    protected final LocalDate from, to;\n    protected BaseReport(LocalDate from, LocalDate to) { this.from = from; this.to = to; }\n    public final byte[] generate() { return render(fetchRows()); }   \/\/ template method\n    protected abstract List&lt;Row&gt; fetchRows();\n    protected abstract byte[] render(List&lt;Row&gt; rows);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">When to use which<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Interface<\/strong> when unrelated classes should share a contract (EmailNotifier and SmsNotifier), or when a class needs several types at once.<\/li>\n\n\n<li><strong>Abstract class<\/strong> when related classes share state and part of the algorithm, as in the template-method report above.<\/li>\n\n\n<li>A common design uses both: an interface for the contract, and an abstract base class that implements part of it.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Java 8 and later<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Default methods let interfaces add behaviour without breaking existing implementations; that is how <code>List.forEach<\/code> and <code>Collection.stream()<\/code> were added. If two interfaces give the same default method, the class must override it and can call one with <code>A.super.method()<\/code>. Interfaces still cannot hold instance state, which is the line that remains.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Follow-ups<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can an abstract class have no abstract methods? (Yes, to stop direct instantiation.)<\/li>\n\n\n<li>What is a functional interface?<\/li>\n\n\n<li>Can an interface extend a class?<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><em>This answer was written by Debugger&#8217;s Space as practice material. It is asked in most Indian IT services interviews (TCS, Infosys, Wipro, HCLTech, Tech Mahindra, LTIMindtree, Accenture, Cognizant, Capgemini, IBM). See each company&#8217;s hiring steps and practice questions on <a href=\"https:\/\/www.debuggersspace.com\/companies\">Debugger&#8217;s Space<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract class versus interface in Java: state, constructors, multiple inheritance, default and static methods since Java 8, and when to choose each.<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[263],"tags":[291,234,236,235,231,237,229,264,233,266,228,232,230],"class_list":["post-1039","post","type-post","status-publish","format-standard","hentry","category-common-interview-questions","tag-abstract-class-vs-interface","tag-accenture","tag-capgemini","tag-cognizant","tag-hcltech","tag-ibm","tag-infosys","tag-java-interview-questions","tag-ltimindtree","tag-oop-interview-questions","tag-tcs","tag-tech-mahindra","tag-wipro"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Himanshu Namdeo","author_link":"https:\/\/blog.debuggersspace.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Abstract class versus interface in Java: state, constructors, multiple inheritance, default and static methods since Java 8, and when to choose each.","_links":{"self":[{"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/1039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/comments?post=1039"}],"version-history":[{"count":1,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/1039\/revisions"}],"predecessor-version":[{"id":1080,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/1039\/revisions\/1080"}],"wp:attachment":[{"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/media?parent=1039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/categories?post=1039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.debuggersspace.com\/index.php\/wp-json\/wp\/v2\/tags?post=1039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}